Avatar of Lico_w
Lico_w

asked on 

VBScript Permission Problem

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
VB ScriptVisual Basic ClassicProgramming

Avatar of undefined
Last Comment
Lico_w

8/22/2022 - Mon