H
hlngus
Got the following to work only on subfolder, but it want to make it
work for main folder and subfolders. This routine checks for files
updated within last 90 days that contain the word "translate" in them.
Sub DoIt()
Dim i As Integer
Dim sLoc As String
Dim vFiles As Variant
Dim vFolders As Variant
Dim Filename As String
Dim outfile As String
' The following folder with 00 subfolders works, when there are no
subfolders below
sLoc = "c:\mainfolder\00\"
vFiles = FillFileNames(sLoc)
vFolders = FillFolders(sLoc)
Dim n As Integer
n = 0
' Gets type mismatch here when search from main folder, and sLoc = "c:
\mainfolder\"
For i = LBound(vFiles) To UBound(vFiles)
'Debug.Print vFiles(i)
Dim L As Long, S As String, FileNum As Integer
FileNum = FreeFile
Filename = vFiles(i)
Open Filename For Binary Access Read Shared As
#FileNum
L = LOF(FileNum)
S = Space$(L)
Get #1, , S
Close #FileNum
If InStr(1, S, "translate") And DateDiff("d", Now,
FileDateTime(vFiles(i))) > -90 Then
n = n + 1
Debug.Print vFiles(i) & " old eps file " & n & " " &
Format(FileDateTime(vFiles(i)), "yyyymmdd") & " " & DateDiff("d", Now,
FileDateTime(vFiles(i)))
End If
Next i
' This works with the following 3 lines commented out, , when there
are no subfolders below.
'For i = LBound(vFolders) To UBound(vFolders)
' Debug.Print vFolders(i)
'Next i
Debug.Print "end"
End Sub
Function FillFolders(sLoc As String) As Variant
Dim sFolder As String
Dim sFolders() As String
sFolder = Dir(sLoc, vbDirectory)
Do While sFolder <> ""
If sFolder <> "." And sFolder <> ".." Then
If (GetAttr(sLoc & sFolder) And vbDirectory) = vbDirectory Then
ReDim Preserve sFolders(i)
sFolders(i) = sFolder
i = i + 1
End If
End If
sFolder = Dir
Loop
FillFolders = sFolders()
End Function
Function FillFileNames(sLoc As String) As Variant
Dim i As Integer
Dim sFileNames() As String
If Dir(sLoc) <> "" Then
With Application.FileSearch
.LookIn = "c:\mainfolder\00\"
' problem when search from main folder, and LookIn= "c:
\mainfolder\"
.Filename = "."
.SearchSubFolders = True
.Execute
For i = 0 To .FoundFiles.Count - 1
ReDim Preserve sFileNames(i)
sFileNames(i) = .FoundFiles(i + 1)
Next i
End With
FillFileNames = sFileNames()
End If
End Function
Thanks for any reply.
work for main folder and subfolders. This routine checks for files
updated within last 90 days that contain the word "translate" in them.
Sub DoIt()
Dim i As Integer
Dim sLoc As String
Dim vFiles As Variant
Dim vFolders As Variant
Dim Filename As String
Dim outfile As String
' The following folder with 00 subfolders works, when there are no
subfolders below
sLoc = "c:\mainfolder\00\"
vFiles = FillFileNames(sLoc)
vFolders = FillFolders(sLoc)
Dim n As Integer
n = 0
' Gets type mismatch here when search from main folder, and sLoc = "c:
\mainfolder\"
For i = LBound(vFiles) To UBound(vFiles)
'Debug.Print vFiles(i)
Dim L As Long, S As String, FileNum As Integer
FileNum = FreeFile
Filename = vFiles(i)
Open Filename For Binary Access Read Shared As
#FileNum
L = LOF(FileNum)
S = Space$(L)
Get #1, , S
Close #FileNum
If InStr(1, S, "translate") And DateDiff("d", Now,
FileDateTime(vFiles(i))) > -90 Then
n = n + 1
Debug.Print vFiles(i) & " old eps file " & n & " " &
Format(FileDateTime(vFiles(i)), "yyyymmdd") & " " & DateDiff("d", Now,
FileDateTime(vFiles(i)))
End If
Next i
' This works with the following 3 lines commented out, , when there
are no subfolders below.
'For i = LBound(vFolders) To UBound(vFolders)
' Debug.Print vFolders(i)
'Next i
Debug.Print "end"
End Sub
Function FillFolders(sLoc As String) As Variant
Dim sFolder As String
Dim sFolders() As String
sFolder = Dir(sLoc, vbDirectory)
Do While sFolder <> ""
If sFolder <> "." And sFolder <> ".." Then
If (GetAttr(sLoc & sFolder) And vbDirectory) = vbDirectory Then
ReDim Preserve sFolders(i)
sFolders(i) = sFolder
i = i + 1
End If
End If
sFolder = Dir
Loop
FillFolders = sFolders()
End Function
Function FillFileNames(sLoc As String) As Variant
Dim i As Integer
Dim sFileNames() As String
If Dir(sLoc) <> "" Then
With Application.FileSearch
.LookIn = "c:\mainfolder\00\"
' problem when search from main folder, and LookIn= "c:
\mainfolder\"
.Filename = "."
.SearchSubFolders = True
.Execute
For i = 0 To .FoundFiles.Count - 1
ReDim Preserve sFileNames(i)
sFileNames(i) = .FoundFiles(i + 1)
Next i
End With
FillFileNames = sFileNames()
End If
End Function
Thanks for any reply.