troubleshooting Question

VBScript Permission Problem

Avatar of Lico_w
Lico_w asked on
VB ScriptVisual Basic ClassicProgramming
8 Comments1 Solution515 ViewsLast Modified:
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 _


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 _
End Sub
Join our community to see this answer!
Unlock 1 Answer and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros