Hi all

I have written this script to report on the files in certain folder
and in its subfolders.

It works fine but it gives an error if the folder it is trying to
access does not have NTFS permissions for the user in whose context
the script is run.

I have tried inserting the line "On Error Resume Next" and this makes
so that no error is genrated but still the script stops recursing into
the folders and exits.

How can I make so that if the script does not have access to a
subfolder it skips it and continues to attempt accessing the other
subfolders???

Thanks!!!





' *** Last access date for files in a folder and in its subfolders ***

on error resume next



Set shell = Wscript.CreateObject("WScript.Shell")
Set FSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = FSO.GetFolder("c:\foldert")
Set REPORTFILE = fso.CreateTextFile("REPORT.csv")
call Recurse(objfolder)




Sub Recurse(objFolder)

For Each MYFILE In objfolder.Files

MYLINE = objfolder.path & "," & MYFILE.Name & "," &
MYFILE.DateLastAccessed & "," & MYFILE.Size
REPORTFILE.writeline MYLINE
Next

For each objSubFolder in objFolder.SubFolders

Recurse(objSubfolder)

Next
End Sub

REPORTFILE.close

Re: script stops execution on error by Torgeir

Torgeir
Wed Sep 15 08:13:37 CDT 2004

Mark Radant wrote:

> Hi all
>
> I have written this script to report on the files in certain folder
> and in its subfolders.
>
> It works fine but it gives an error if the folder it is trying to
> access does not have NTFS permissions for the user in whose context
> the script is run.
>
> I have tried inserting the line "On Error Resume Next" and this makes
> so that no error is genrated but still the script stops recursing into
> the folders and exits.
>
> How can I make so that if the script does not have access to a
> subfolder it skips it and continues to attempt accessing the other
> subfolders???
>
> Thanks!!!
Hi

Put the "On Error Resume Next" line inside the Recurse sub
(at the top), and see if that helps.


--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx