Results 1 to 3 of 3

Thread: Find Files Overflow

  1. #1

    Thread Starter
    Hyperactive Member PITBULLCJR's Avatar
    Join Date
    Nov 1999
    Location
    New York
    Posts
    408

    Find Files Overflow

    Well the find files api works well at this site. I changed a few things because I am getting an overflow and I made it so you can have it just check the dir you are in or do sub directories too. Even with the code unchanged it still seems to give me an overflow when I am searching for my mp3s on my harddrive. I have 1077 and it dies at 1077. If I copy an mp3 and put it in the same dir so now i have 1078 it then dies at 1078. Here is the coding.

    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
    4. Private Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" (ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long
    5. Private Declare Function GetFileAttributes Lib "kernel32" Alias "GetFileAttributesA" (ByVal lpFileName As String) As Long
    6. Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long
    7.  
    8. Const MAX_PATH = 260
    9. Const MAXDWORD = &HFFFF
    10. Const INVALID_HANDLE_VALUE = -1
    11. Const FILE_ATTRIBUTE_ARCHIVE = &H20
    12. Const FILE_ATTRIBUTE_DIRECTORY = &H10
    13. Const FILE_ATTRIBUTE_HIDDEN = &H2
    14. Const FILE_ATTRIBUTE_NORMAL = &H80
    15. Const FILE_ATTRIBUTE_READONLY = &H1
    16. Const FILE_ATTRIBUTE_SYSTEM = &H4
    17. Const FILE_ATTRIBUTE_TEMPORARY = &H100
    18.  
    19. Private Type FILETIME
    20.     dwLowDateTime As Long
    21.     dwHighDateTime As Long
    22. End Type
    23.  
    24. Private Type WIN32_FIND_DATA
    25.     dwFileAttributes As Long
    26.     ftCreationTime As FILETIME
    27.     ftLastAccessTime As FILETIME
    28.     ftLastWriteTime As FILETIME
    29.     nFileSizeHigh As Long
    30.     nFileSizeLow As Long
    31.     dwReserved0 As Long
    32.     dwReserved1 As Long
    33.     cFileName As String * MAX_PATH
    34.     cAlternate As String * 14
    35. End Type
    36. Function StripNulls(OriginalStr As String) As String
    37.     If (InStr(OriginalStr, Chr(0)) > 0) Then
    38.         OriginalStr = Left(OriginalStr, InStr(OriginalStr, Chr(0)) - 1)
    39.     End If
    40.     StripNulls = OriginalStr
    41. End Function
    42.  
    43. Function FindFilesAPI(path As String, SearchStr As String, FileCount As Long, DirCount As Long, subdir As Boolean)
    44.     'KPD-Team 1999
    45.     'E-Mail: [email][email protected][/email]
    46.     'URL: [url]http://www.allapi.net/[/url]
    47.  
    48.     Dim FileName As String ' Walking filename variable...
    49.     Dim DirName As String ' SubDirectory Name
    50.     Dim dirNames() As String ' Buffer for directory name entries
    51.     Dim nDir As Long ' Number of directories in this path
    52.     Dim i As Long ' For-loop counter...
    53.     Dim hSearch As Long ' Search Handle
    54.     Dim WFD As WIN32_FIND_DATA
    55.     Dim Cont As Long
    56.     If Right(path, 1) <> "\" Then path = path & "\"
    57.     ' Search for subdirectories.
    58.     nDir = 0
    59.     ReDim dirNames(nDir)
    60.     Cont = True
    61.     hSearch = FindFirstFile(path & "*", WFD)
    62.     If hSearch <> INVALID_HANDLE_VALUE Then
    63.         Do While Cont
    64.         DirName = StripNulls(WFD.cFileName)
    65.         ' Ignore the current and encompassing directories.
    66.         If (DirName <> ".") And (DirName <> "..") Then
    67.             ' Check for directory with bitwise comparison.
    68.             If GetFileAttributes(path & DirName) And FILE_ATTRIBUTE_DIRECTORY Then
    69.                 dirNames(nDir) = DirName
    70.                 DirCount = DirCount + 1
    71.                 nDir = nDir + 1
    72.                 ReDim Preserve dirNames(nDir)
    73.             End If
    74.         End If
    75.         Cont = FindNextFile(hSearch, WFD) 'Get next subdirectory.
    76.         Loop
    77.         Cont = FindClose(hSearch)
    78.     End If
    79.     ' Walk through this directory and sum file sizes.
    80.     hSearch = FindFirstFile(path & SearchStr, WFD)
    81.     Cont = True
    82.     If hSearch <> INVALID_HANDLE_VALUE Then
    83.         While Cont
    84.             FileName = StripNulls(WFD.cFileName)
    85.             If (FileName <> ".") And (FileName <> "..") Then
    86.                 FindFilesAPI = FindFilesAPI + (WFD.nFileSizeHigh * MAXDWORD) + WFD.nFileSizeLow
    87.                 FileCount = FileCount + 1
    88.                 List1.AddItem path & FileName
    89.             End If
    90.             Cont = FindNextFile(hSearch, WFD) ' Get next file
    91.         Wend
    92.         Cont = FindClose(hSearch)
    93.     End If
    94.     ' If there are sub-directories...
    95.     If subdir = True Then 'if the sub directories option is on
    96.     If nDir > 0 Then
    97.         ' Recursively walk into them...
    98.         For i = 0 To nDir - 1
    99.             FindFilesAPI = FindFilesAPI + FindFilesAPI(path & dirNames(i) & "\", SearchStr, FileCount, DirCount, True)
    100.         Next i
    101.     End If
    102.     End If
    103. End Function
    104. Sub Command1_Click()
    105.     Dim SearchPath As String, FindStr As String
    106.     Dim FileSize As Long
    107.     Dim NumFiles As Long, NumDirs As Long
    108.     Screen.MousePointer = vbHourglass
    109.     List1.Clear
    110.     SearchPath = "C:\windows\desktop\mp3s\"
    111.     FindStr = "*.mp3"
    112.     FileSize = FindFilesAPI(SearchPath, FindStr, NumFiles, NumDirs, True)
    113.     Text3.Text = NumFiles & " Files found in " & NumDirs + 1 & " Directories"
    114.     Text4.Text = "Size of files found under " & SearchPath & " = " & Format(FileSize, "#,###,###,##0") & " Bytes"
    115.     Screen.MousePointer = vbDefault
    116. End Sub
    Sincerely,
    Chris


    Email: [email protected]
    AIM: KnightsOfTheMoon
    WebPage: http://kom.wicre.com
    ----------------
    VB6 Professional
    Abit ST6-RAID
    1000 MHZ
    512 MB PC133 Ram
    Nvidia GeForce 2 Ultra 64 MB
    Maxtor 81.9 Gig
    Win 98 SE

  2. #2
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923
    I use that KDT-API code all the time and it's never given me any problems...what line is it busting on?

  3. #3

    Thread Starter
    Hyperactive Member PITBULLCJR's Avatar
    Join Date
    Nov 1999
    Location
    New York
    Posts
    408

    Whats odd is...

    When I hit debug it is highlighting.

    FileSize = FindFilesAPI(SearchPath, FindStr, NumFiles, NumDirs, True)

    But the funny thing is, that all the variables are extrememly low. the highest one is NumFiles which is just a tad bit over 1000.

    DOH I Just tried it again to check to see what the other variables were and now it works. I know why too. I had a retarded mp3 that was corrupted. I just deleted that a little while ago to. I have a good feeling that was the problem. Sorry Chris
    Sincerely,
    Chris


    Email: [email protected]
    AIM: KnightsOfTheMoon
    WebPage: http://kom.wicre.com
    ----------------
    VB6 Professional
    Abit ST6-RAID
    1000 MHZ
    512 MB PC133 Ram
    Nvidia GeForce 2 Ultra 64 MB
    Maxtor 81.9 Gig
    Win 98 SE

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