Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Permission Denied Problem

Status
Not open for further replies.

Wetzel

MIS
Jan 5, 2005
4
US
I have a script that is recursively looking through an entire drive. It works great up until the point when I come across a directory that I do not have permission to get into. (for example C:\System Volume Information)

I was wondering if anyone knows of a way that I can circumvent this; to skip over and check out the other directories instead.

here's my script that gives me this error:
I:\My Documents\Filemaker Script\tester.vbs(22, 5) Microsoft VBScript runtime error: Permission denied
Code:
Option Explicit

Dim ObjFSO
Dim ObjStartDrive    
Dim ObjFolder    
Dim Folder    
Dim ObjFile    

Set ObjFSO = CreateObject("Scripting.FileSystemObject")
Set ObjStartDrive = ObjFSO.GetFolder("C:\")

For Each ObjFolder In ObjStartDrive.SubFolders
    FindFiles(ObjFolder)
Next
    
'##############################################
Sub FindFiles(Folder)

Set Folder = ObjFSO.GetFolder(Folder)
	Wscript.Echo Folder
	Wscript.Echo Folder.Type
    For Each ObjFile In Folder.Files
           If Instr(1, ObjFile.Name, ".fmp", 1) Then
                   Wscript.Echo ObjFile.Path
                   Wscript.Echo ObjFile.DateCreated    
           Else
           End If 
    Next

If Folder.SubFolders.Count > 0 Then
    For Each Folder In Folder.SubFolders
        FindFiles(Folder.Path)
    Next
End If

End Sub
'################################################

thanks for any help you can give

-Mark Wetzel
 
Have you tried putting :

On error resume next

on the line before "for each objfolder....

?
 
in your sub you call trying to do this

Set Folder = ObjFSO.GetFolder(Folder)

at this time the 'Folder' variable already contains a Folder object. i would say that the GetFolder method is expecting a string. anyway seeing as Folder is already a folder object you say dont need the line:

Set Folder = ObjFSO.GetFolder(Folder)

 
Wetzel,

Further to mrmovie's observation, it is this.
[tt]
FindFiles ObjFolder[red].path[/red]
[/tt]
And in the sub, avoid name collision.
[tt]
Sub FindFiles(Folder[blue]spec[/blue])
Set Folder = ObjFSO.GetFolder(Folder[blue]spec[/blue])
'etc continue the same
[/tt]
Permission problem would not surface. The fso won't even see it. Seldom anybody has all the rights to the files and folders.

- tsuji
 
i dont think you need this first loop either., it is handled in your sun

For Each ObjFolder In ObjStartDrive.SubFolders
FindFiles(ObjFolder)
Next

you should find this will do

FindFiles(ObjStartDrive)

providing you get rid of the

Set Folder = ObjFSO.GetFolder(Folder)

saying that as Tsuji suggested the GetFolder method might implicitly convert the Folder object to a string but ive never tested it so to clarify:

Option Explicit

Dim ObjFSO
Dim ObjStartDrive
Dim ObjFolder
Dim Folder
Dim ObjFile

Set ObjFSO = CreateObject("Scripting.FileSystemObject")
Set ObjStartDrive = ObjFSO.GetFolder("C:\")

FindFiles(ObjStartDrive)

'##############################################
Sub FindFiles(Folder)
Dim anotherFolder
Wscript.Echo Folder.Name
Wscript.Echo Folder.Type
For Each ObjFile In Folder.Files
If Instr(1, ObjFile.Name, ".fmp", 1) Then
Wscript.Echo ObjFile.Path
Wscript.Echo ObjFile.DateCreated
Else
End If
Next

If Folder.SubFolders.Count > 0 Then
For Each anotherFolder In Folder.SubFolders
FindFiles(anotherFolder)
Next
End If

End Sub
'################################################
 
Thank you very much for all your input. It's helped a lot.

I thought I tried using the 'On Error Resume Next' before, and I got an error where it would just repeat failing on the same directory. forever.

But, I tried it again today, and sure enough, it works. I am able to recursively search through the directory structure while skipping over the directories that I do not have permissions on.

Thanks Jerz, mrmovie, and tsuji for your help on this. Much appreciated.

-wetzel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top