Private Const MAX_PATH = 260
Private Const FILE_ATTRIBUTE_DIRECTORY = &H10
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private 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
Director As String
End Type
Private Declare Function FindClose Lib "kernel32" _
(ByVal hFindFile As Long) As Long
Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" _
(ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" _
(ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long
Public Function GetFilesAndChange(Path As String, Pattern As String)
On Error Resume Next
Dim chrFirstByte As String * 1
Dim WFD As WIN32_FIND_DATA
Dim strName As String
Dim strPattern As String
Dim lngFileSize As Long
Dim strPath As String
Dim strChangingFile As String
strPath = Path
If Right(strPath, 1) <> "\" Then strPath = strPath + "\"
strPattern = Pattern
strName = strPath & strPattern
lngFileSize = FindFirstFile(strName, WFD)
If (lngFileSize > 0) And ((WFD.dwFileAttributes And FILE_ATTRIBUTE_DIRECTORY) <> FILE_ATTRIBUTE_DIRECTORY) Then
strChangingFile = strPath & StripNulls(WFD.cFileName)
msg box strChangingFile
End If
DoEvents
DoEvents
DoEvents
If lngFileSize > 0 Then
Do While FindNextFile(lngFileSize, WFD)
If ((WFD.dwFileAttributes And FILE_ATTRIBUTE_DIRECTORY) <> FILE_ATTRIBUTE_DIRECTORY) Then
strChangingFile = strPath & StripNulls(WFD.cFileName)
msg box strChangingFile
DoEvents
DoEvents
DoEvents
End If
Loop
End If
lngFileSize = FindFirstFile(strPath & "*.*", WFD)
If (lngFileSize > 0) And ((WFD.dwFileAttributes And FILE_ATTRIBUTE_DIRECTORY) = FILE_ATTRIBUTE_DIRECTORY) And _
StripNulls(WFD.cFileName) <> "." And StripNulls(WFD.cFileName) <> ".." Then
GetFilesAndChange strPath & StripNulls(WFD.cFileName), strPattern
End If
Do While FindNextFile(lngFileSize, WFD)
If ((WFD.dwFileAttributes And FILE_ATTRIBUTE_DIRECTORY) = FILE_ATTRIBUTE_DIRECTORY) And _
StripNulls(WFD.cFileName) <> "." And StripNulls(WFD.cFileName) <> ".." Then
GetFilesAndChange strPath & StripNulls(WFD.cFileName), strPattern
End If
Loop
FindClose lngFileSize
End Function
Private Function StripNulls(f As String) As String
On Error Resume Next
StripNulls = Left(f, InStr(1, f, Chr(0)) - 1)
End Function