Bakeyman
Technical User
- Mar 3, 2008
- 8
I'm trying to write a script to drill through a specified folder path and return the last modified date of all files it sees out to a text file. I've got everything working, except the part where I create the text file and then try to open it. If I run the script twice in a row (so it doesn't have to create the file and then open it) the script runs fine. There seems to be some problem centered around creating the file and opening it during the same script.
Disclaimer: I am not a programmer, so don't laugh too hard at my code!
Here's my code:
Disclaimer: I am not a programmer, so don't laugh too hard at my code!
Here's my code:
Code:
Option Explicit
'on error resume next
Dim objFSO
Dim objFolder
Dim colFiles
Dim objSubFolder
Dim objSubFile
Dim strFolder
Dim File
Dim objFile
Dim colFolders
Dim path
Dim filecreate
Dim filetxt
Dim strLine
Dim input
Dim WriteStuff
Input = InputBox("Enter folder path")
strFolder = "c:\"& Input
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strFolder)
Set colFiles = objFolder.Files
filetxt= "c:\FileReports\"& Input &".txt"
If not objFSO.FileExists(filetxt) Then
set filecreate = objFSO.CreateTextFile(filetxt, True)
Set WriteStuff = objFSO.OpenTextFile(filetxt, 8, True)
Else
Set WriteStuff = objFSO.OpenTextFile(filetxt, 8, True)
End if
For Each File in colFiles
set objFile = objFSO.GetFile(strFolder & "\" & File.Name)
WriteStuff.WriteLine(objFile.Path & " - " & "Last accessed: " & objFile.DateLastAccessed)
Next
ScanSubFolders(objFolder)
Sub ScanSubFolders(objFolder)
Set colFolders = objFolder.SubFolders
For Each objSubFolder In colFolders
Set colFiles = objSubFolder.Files
For Each objFile in Colfiles
WriteStuff.WriteLine(objFile.Path & " - " & "Last accessed: " & objFile.DateLastAccessed)
Next
ScanSubFolders(objSubFolder)
Next
End Sub
set objFSO = Nothing
set objFolder = Nothing
set colFiles = Nothing
set objSubFolder = Nothing
set objSubFile = Nothing
set strFolder = Nothing
set File = Nothing
set objFile = Nothing
set colFolders = Nothing
set path = Nothing
set filecreate = Nothing
set filetxt = Nothing
set strLine = Nothing
set input = Nothing
set WriteStuff = Nothing
wscript.Quit