I am trying to write some VBScript to cycle through all of the directories on my machine, find any files which have been modified in the last hour and output the full filename to a text file in it's current location. The file works fine when sat in a folder on my machine but as soon as I drop it on the root dir I get permission errors. I think this must be because I don't have read permissions on certain directories, is there a way around this? My code is below:
Dim sCurPath
sCurPath = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".")
'createDirectory = "C:\Documents and Settings\T104ahe\Desktop\Menu\TestScript\myNewFolder"
createFile = "\Modified_Files_List.txt"
' Create the File System Object
Set createobjFSO = CreateObject("Scripting.FileSystemObject")
'Set createobjFolder = createobjFSO.CreateFolder(createDirectory)
Set createobjFile = createobjFSO.CreateTextFile(sCurPath & createFile)
Wscript.Echo "File: " & createDirectory & createFile & " successfully created."
'--------------------------------------------------------
hourAgo = DateAdd("h", -1, Now)
'destDir = "C:\Documents and Settings\T104ahe\Desktop\Menu\TestScript\filesModified"
strFolder = sCurPath
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strFolder)
'WScript.Echo objFolder.Path
Set colFiles = objFolder.Files
For Each objFile In colFiles
If objFile.DateLastModified > hourAgo Then _
createobjFile.WriteLine(objFile.path)
Next
ShowSubFolders(objFolder)
Sub ShowSubFolders(objFolder)
Set colFolders = objFolder.SubFolders
For Each objSubFolder In colFolders
'WScript.Echo objSubFolder.Path
Set colFiles = objSubFolder.Files
For Each objFile In colFiles
If objFile.DateLastModified > hourAgo Then _
createobjFile.WriteLine(objFile.path)
Next
ShowSubFolders(objSubFolder)
Next
End Sub
Our community of experts have been thoroughly vetted for their expertise and industry experience.
The Most Valuable Expert award recognizes technology experts who passionately share their knowledge with the community, demonstrate the core values of this platform, and go the extra mile in all aspects of their contributions. This award is based off of nominations by EE users and experts. Multiple MVEs may be awarded each year.
The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.