Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

list files to a text files by date

Status
Not open for further replies.

incron

Technical User
Mar 16, 2002
60
US
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 guess you put up a "on error resume next" at that place purely to avoid the error of defining the constants multiple times. It is not a good use of it nor a good way to tolerate const defined in a loop. Take out the "on error resume next" and put the const statement outside the loop, perhaps to the top of the sub, and see what error you come up with.
 
Hi tsuji - thanks for the quick reply

I took out the line and posted up top and took out the
"on Error Resume Next" error - unfortunately the result was the same. It listed every file but that one. It is a setup.exe file I don't think that should make any difference.
 
Hi guys me again - additional info

I turned on the echo logic and added and additional file that is also about a year old - a readme.txt file dated 12/4/2006 and again it read the file (as evident by the msgbox) but it didn't list the file. Again it listed other files oldest being
a readme.txt file dated 3/27/2006. Here is part of the logic that is listing the files - am I missing something...??

If (DateDiff("D",objFile.DateLastModified,Date)) > 10 Then
 
Also note that you do not list the files at the very top objStartFolder, only the files in its subfolders. Is that setup.exe directly under objStartFolder?
 
Yes thats it! - Good catch!! I thought since it was reading the file it was processing the file - not so. Excellent catch!! - I repeated the processing logic at the top for the root folder. Sometimes you stare at something for so many days you start to get code blind...!!! - Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top