Results 1 to 6 of 6

Thread: find files api

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Location
    Newcastle
    Posts
    260

    Talking find files api

    Hi All.
    I use the below code to search for files of a given type in my program..some of the users have asked for a progress bar to see where the search is at only I have NO idea where to insert the bit of code do do this can any one help please
    VB Code:
    1. Function FindFilesAPI(path As String, SearchStr As String, FileCount As Integer, DirCount As Integer)
    2. 'On Error GoTo trap:
    3.  
    4.      ' Walking filename variable...
    5.     Dim DirName As String ' SubDirectory Name
    6.     Dim dirNames() As String ' Buffer for directory name entries
    7.     Dim nDir As Integer ' Number of directories in this path
    8.     Dim i As Integer ' For-loop counter...
    9.     Dim hSearch As Long ' Search Handle
    10.     Dim WFD As WIN32_FIND_DATA
    11.     Dim Cont As Integer
    12.     If Right(path, 1) <> "\" Then path = path & "\"
    13.     ' Search for subdirectories.
    14.     nDir = 0
    15.     ReDim dirNames(nDir)
    16.     Cont = True
    17.     hSearch = FindFirstFile(path & "*", WFD)
    18.     If hSearch <> INVALID_HANDLE_VALUE Then
    19.         Do While Cont
    20.         DirName = StripNulls(WFD.cFileName)
    21.         ' Ignore the current and encompassing directories.
    22.         If (DirName <> ".") And (DirName <> "..") Then
    23.             ' Check for directory with bitwise comparison.
    24.             If GetFileAttributes(path & DirName) And FILE_ATTRIBUTE_DIRECTORY Then
    25.                 dirNames(nDir) = DirName
    26.                 DirCount = DirCount + 1
    27.                 nDir = nDir + 1
    28.                 ReDim Preserve dirNames(nDir)
    29.             End If
    30.         End If
    31.         Cont = FindNextFile(hSearch, WFD) 'Get next subdirectory.
    32.         Loop
    33.         Cont = FindClose(hSearch)
    34.     End If
    35.     ' Walk through this directory and sum file sizes.
    36.     hSearch = FindFirstFile(path & SearchStr, WFD)
    37.     Cont = True
    38.     If hSearch <> INVALID_HANDLE_VALUE Then
    39.         While Cont
    40.             FileName = StripNulls(WFD.cFileName)
    41.             If (FileName <> ".") And (FileName <> "..") Then
    42.                 FindFilesAPI = FindFilesAPI + (WFD.nFileSizeHigh * MAXDWORD) + WFD.nFileSizeLow
    43.                 FileCount = FileCount + 1
    44.                 lstFilesfound.AddItem path & FileName
    45.                 DoEvents
    46.             End If
    47.             Cont = FindNextFile(hSearch, WFD) ' Get next file
    48.         Wend
    49.         Cont = FindClose(hSearch)
    50.     End If
    51.     ' If there are sub-directories...
    52.     If nDir > 0 Then
    53.         ' Recursively walk into them...
    54.         For i = 0 To nDir - 1
    55.             FindFilesAPI = FindFilesAPI + FindFilesAPI(path & dirNames(i) & "\", SearchStr, FileCount, DirCount)
    56.         Next i
    57.     End If
    58. 'End Function
    59.  
    60. 'trap:
    61. 'Call crash
    62.  
    63. End Function


    many thanks Chris

  2. #2
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    You would have to know the number of files or dirs, so unless you do almost everything twice so you can count the files first then loop through them and increase the value of the progress bar I don't see a way...


    Has someone helped you? Then you can Rate their helpful post.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Location
    Newcastle
    Posts
    260
    thats what I thought....do u know of any other way to do this type of search??

    Chris

  4. #4
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    In the codebank I have two threads about searching. One for files and one for folders. Search for them... Maybe it is better


    Has someone helped you? Then you can Rate their helpful post.

  5. #5
    Fanatic Member
    Join Date
    Jun 2003
    Location
    IL
    Posts
    739
    This is just a thought and I have no code to demonstrate, but maybe the idea can help. You could always find the size of the directory and it sub-directories (Storage wise I mean). Then while you are searching keep adding the total size of the files to a variable and each time divide it by the total size you are searching through. Obviously it wouldn't be an accurate progress since some files are bigger than others, but it still shows some type of progress . I also don't completly understand all of your code, so I can't help you on where you could place this.

  6. #6
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Not bad. I think with FSO you can get sizes...


    Has someone helped you? Then you can Rate their helpful post.

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