Hey guys
I have developed a code that list all files in folders and sub folders based on a specific date and then write the results to a text file it works great except one of the files in my test folder is never written even though it is within the parameters of the list argument. Below I am looking at every file and writing the ones older than 10 days old to a text file. I have turned on the echo options and observed that the logic is seeing the file - it just wont list it. I have verified the file is not read only and the security settings is normal. The file is date 1/16/2006 I'm listing everything older than 10 days. Thanks in advance for any ideas. Below is the code:
dim lcnfl, lcncontents
Set filesys = CreateObject("Scripting.FileSystemObject")
Set lcnfl = filesys.OpenTextFile("locnfile.txt", 1 , false)
lcncontents = lcnfl.ReadLine
lcnfl.close
Set filesys=Nothing
TargetFile = lcncontents
Set objFSO = CreateObject("Scripting.FileSystemObject")
objStartFolder = lcncontents
Set objFolder = objFSO.GetFolder(objStartFolder)
'Wscript.Echo objFolder.Path
Set colFiles = objFolder.Files
For Each objFile in colFiles
'Wscript.Echo objFile.Name
Next
'Wscript.Echo
ShowSubfolders objFSO.GetFolder(objStartFolder)
Sub ShowSubFolders(Folder)
For Each Subfolder in Folder.SubFolders
'Wscript.Echo Subfolder.Path
Set objFolder = objFSO.GetFolder(Subfolder.Path)
Set colFiles = objFolder.Files
For Each objFile in colFiles
'If the difference between todays date and the last modified(saved) date of the file is less the number
'specfied then write it to the uploadlist.txt file
If (DateDiff("D",objFile.DateLastModified,Date)) > 10 Then
'remember - the ">" symbol is going to include everything (all files) older (in days) than the number specifed
'and the "<" symbol is going to include everything (all files) newer (in days) than the number specifed
on Error Resume Next
dim filesys, filetxt
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set filesys = CreateObject("Scripting.FileSystemObject")
Set filetxt = filesys.OpenTextFile("uploadfilelist.txt", ForAppending, True)
filetxt.WriteLine(objFile.Name)
filetxt.Close
End If
'Wscript.Echo objFile.Name
Next
'Wscript.Echo
ShowSubFolders Subfolder
Next
End Sub
I have developed a code that list all files in folders and sub folders based on a specific date and then write the results to a text file it works great except one of the files in my test folder is never written even though it is within the parameters of the list argument. Below I am looking at every file and writing the ones older than 10 days old to a text file. I have turned on the echo options and observed that the logic is seeing the file - it just wont list it. I have verified the file is not read only and the security settings is normal. The file is date 1/16/2006 I'm listing everything older than 10 days. Thanks in advance for any ideas. Below is the code:
dim lcnfl, lcncontents
Set filesys = CreateObject("Scripting.FileSystemObject")
Set lcnfl = filesys.OpenTextFile("locnfile.txt", 1 , false)
lcncontents = lcnfl.ReadLine
lcnfl.close
Set filesys=Nothing
TargetFile = lcncontents
Set objFSO = CreateObject("Scripting.FileSystemObject")
objStartFolder = lcncontents
Set objFolder = objFSO.GetFolder(objStartFolder)
'Wscript.Echo objFolder.Path
Set colFiles = objFolder.Files
For Each objFile in colFiles
'Wscript.Echo objFile.Name
Next
'Wscript.Echo
ShowSubfolders objFSO.GetFolder(objStartFolder)
Sub ShowSubFolders(Folder)
For Each Subfolder in Folder.SubFolders
'Wscript.Echo Subfolder.Path
Set objFolder = objFSO.GetFolder(Subfolder.Path)
Set colFiles = objFolder.Files
For Each objFile in colFiles
'If the difference between todays date and the last modified(saved) date of the file is less the number
'specfied then write it to the uploadlist.txt file
If (DateDiff("D",objFile.DateLastModified,Date)) > 10 Then
'remember - the ">" symbol is going to include everything (all files) older (in days) than the number specifed
'and the "<" symbol is going to include everything (all files) newer (in days) than the number specifed
on Error Resume Next
dim filesys, filetxt
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set filesys = CreateObject("Scripting.FileSystemObject")
Set filetxt = filesys.OpenTextFile("uploadfilelist.txt", ForAppending, True)
filetxt.WriteLine(objFile.Name)
filetxt.Close
End If
'Wscript.Echo objFile.Name
Next
'Wscript.Echo
ShowSubFolders Subfolder
Next
End Sub