I have two files in this location
1) C:\DATABASE\SAWAHSEMPADAN\DATA\Soil.shp
2) C:\DATABASE\SAWAHSEMPADAN\DATA\LOT\Soil.shp
When I used code below to search files in the directory and sub directory,it able to found only one files in the parent directory. It suppose found two files in the directory. Why could be like this?
Code:Private Declare Function SearchTreeForFile Lib "imagehlp" _ (ByVal RootPath As String, ByVal InputPathName As String, _ ByVal OutputPathBuffer As String) As Long Private Const MAX_PATH = 260 Private Sub Command1_Click() Dim tempstr As String, ret As Long tempstr = String(MAX_PATH, 0) 'Search files in directory and sub directory ret = SearchTreeForFile("C:\DATABASE\", TextBox2.Text + ".shp", tempstr) 'search data shapefile If ret <> 0 Then 'If data found Call Insertsub(tempstr) End If End Sub Private Sub Insertsub(tempstr As String) Dim i As Long Dim sName() As String Dim sPath As String Dim inti As Integer sName = Split(tempstr, "\") 'contains File name' inti = UBound(sName) 'search file name dan show filename with extension dan path location dalam listview Dim lvItem As ListItem Set lvItem = ListView1.ListItems.Add(, , sName(inti)) lvItem.ListSubItems.Add , , "" & GetDirFromFile(tempstr) TextBox3.Text = sName(inti) 'name TextBox4.Text = GetDirFromFile(tempstr) 'path location End Sub Public Function GetDirFromFile(fileName As String) As String GetDirFromFile = Left(fileName, InStrRev(fileName, "\")) End Function




Reply With Quote