Results 1 to 2 of 2

Thread: Help with MSDN coding please!

  1. #1

    Thread Starter
    Hyperactive Member vbzero's Avatar
    Join Date
    Aug 2000
    Location
    Vienna
    Posts
    347

    Exclamation

    Hi there! I've got a problem. The following lines
    will show you a sample part of a MSDN libary code:

    Code:
    Public Const MAX_PATH = 260
    Public Const MAXDWORD = &HFFFF
    Public Const INVALID_HANDLE_VALUE = -1
    Public Const FILE_ATTRIBUTE_ARCHIVE = &H20
    Public Const FILE_ATTRIBUTE_DIRECTORY = &H10
    Public Const FILE_ATTRIBUTE_HIDDEN = &H2
    Public Const FILE_ATTRIBUTE_NORMAL = &H80
    Public Const FILE_ATTRIBUTE_READONLY = &H1
    Public Const FILE_ATTRIBUTE_SYSTEM = &H4
    Public Const FILE_ATTRIBUTE_TEMPORARY = &H100
    
    Type FILETIME
    dwLowDateTime As Long
    dwHighDateTime As Long
    End Type
    
    Type WIN32_FIND_DATA
    dwFileAttributes As Long
    ftCreationTime As FILETIME
    ftLastAccessTime As FILETIME
    ftLastWriteTime As FILETIME
    nFileSizeHigh As Long
    nFileSizeLow As Long
    dwReserved0 As Long
    dwReserved1 As Long
    cFileName As String * MAX_PATH
    cAlternate As String * 14
    End Type
    
    Function FindFilesAPI(strPath As String, SearchStr As String, _
    FileCount As Integer, DirCount As Integer)
    On Error Resume Next
    Dim FileName As String
    Dim DirName As String
    Dim DirNames() As String
    Dim nDir As Integer
    Dim hSearch As Long
    Dim i As Integer
    Dim WFD As WIN32_FIND_DATA
    Dim Cont As Integer
    Dim ErrorCount As Integer
    If Right(strPath, 1) <> "\" Then strPath = strPath & "\"
    nDir = 0
    ReDim DirNames(nDir)
    Cont = True
    hSearch = FindFirstFile(strPath & "*", WFD)
    If hSearch <> INVALID_HANDLE_VALUE Then
    Do While Cont
    DirName = StripNulls(WFD.cFileName)
    If (DirName <> ".") And (DirName <> "..") Then
    If GetFileAttributes(strPath & DirName) And _
    FILE_ATTRIBUTE_DIRECTORY Then
    DirNames(nDir) = DirName
    DirCount = DirCount + 1
    nDir = nDir + 1
    ReDim Preserve DirNames(nDir)
    End If
    End If
    Cont = FindNextFile(hSearch, WFD)
    Loop
    Cont = FindClose(hSearch)
    End If
    hSearch = FindFirstFile(strPath & SearchStr, WFD)
    Cont = True
    If hSearch <> INVALID_HANDLE_VALUE Then
    While Cont
    FileName = StripNulls(WFD.cFileName)
    If (FileName <> ".") And (FileName <> "..") And _
    ((GetFileAttributes(strPath & FileName) And Not _
    FILE_ATTRIBUTE_DIRECTORY)) Then
    FindFilesAPI = FindFilesAPI + (WFD.nFileSizeHigh * _
    MAXDWORD) + WFD.nFileSizeLow
    FileCount = FileCount + 1
    Call NameMp3(FileName, strPath) 'This is a own defined function
    End If
    Cont = FindNextFile(hSearch, WFD)
    Wend
    Cont = FindClose(hSearch)
    End If
    If nDir > 0 Then
    For i = 0 To nDir - 1
    FindFilesAPI = FindFilesAPI + FindFilesAPI(strPath & DirNames(i) _
    & "\", SearchStr, FileCount, DirCount)
    Next i
    End If
    End Function
    ---- There are 3 elements in the WIN32_FIND_DATA type:

    ftCreationTime As FILETIME
    ftLastAccessTime As FILETIME
    ftLastWriteTime As FILETIME


    I don't want to have that elements in that type.
    If I remove this part of code, the FILETIME type
    is also not needed any more.

    But when I do this, the function will return something
    about 207 file(s) found in 58 directories or something
    like that.

    I also removed this part:

    FindFilesAPI = FindFilesAPI + (WFD.nFileSizeHigh * _
    MAXDWORD) + WFD.nFileSizeLow

    ----
    This sample function allows you t o search for
    files in a directory and in its subdirectories.

    The original code also counted the bytes of the files
    and the time when they were created.

    I don't need that to be in this code.

    Any suggestions how to make a nice function for that?

    thx, vbzero

  2. #2

    Thread Starter
    Hyperactive Member vbzero's Avatar
    Join Date
    Aug 2000
    Location
    Vienna
    Posts
    347

    Arrow

    Sorry - if you're wondering where is the function for
    StripNulls... here it is:

    Code:
    Public Function StripNulls(OriginalStr As String) As String
    On Error Resume Next
    If (InStr(OriginalStr, Chr(0)) > 0) Then
    OriginalStr = Left(OriginalStr, _
    InStr(OriginalStr, Chr(0)) - 1)
    End If
    StripNulls = OriginalStr
    End Function
    thx, vbzero

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