Results 1 to 6 of 6

Thread: [RESOLVED] Search files in directory

Threaded View

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Resolved [RESOLVED] Search files in directory

    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
    Last edited by matrik02; Jun 11th, 2008 at 09:07 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width