Re: Path not found error using FSO GetFolder
- From: "J Talbot" <talbotj123@xxxxxxxxx>
- Date: Tue, 4 Sep 2007 11:20:35 +0100
Should add that this is the correct line in the script
objStartFolder = "\\server\files"
"J Talbot" <talbotj123@xxxxxxxxx> wrote in message
news:46dd2e4b$0$3147$9a6e19ea@xxxxxxxxxxxxxxxxxxxxxxxxxxxx
Thanks but this still errors with Path not found on the long UNC path
after listing the previous subfolders, here's what I used after your
modification :
Set objFSO = CreateObject("Scripting.FileSystemObject")
objStartFolder = \\server\files
Set objFolder = objFSO.GetFolder(objStartFolder)
Wscript.Echo objFolder.Path
Wscript.Echo
ShowSubfolders objFSO.GetFolder(objStartFolder)
Function GetFolderFromPath(Path)
On Error Resume Next
Set GetFolderFromPath = Nothing
Set GetFolderFromPath = objFSO.GetFolder(Path)
End Function
Sub ShowSubFolders(Folder)
For Each Subfolder in Folder.SubFolders 'Path Not Found error on
this line
Wscript.Echo Subfolder.Path
If Not GetFolderFromPath(Subfolder.Path) Is Nothing Then
Wscript.Echo
ShowSubFolders Subfolder
End If
Next
End Sub
This is just a test script for part of another project where I need to
list files in folders, however, I need to ignore folders that can't be
accessed and let the script continue for folders that can.
Any other thoughts on the above ? - is it correct ?
Thanks
John
"Anthony Jones" <Ant@xxxxxxxxxxxxxxxx> wrote in message
news:%23C2YcZt7HHA.5164@xxxxxxxxxxxxxxxxxxxxxxx
"J Talbot" <talbotj123@xxxxxxxxx> wrote in message
news:46dd213a$0$22126$9a6e19ea@xxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hipath
I'm using a script to get a list of folders (and subfolders) for a UNC
but I noticed that if the script tries to get hold of a subfolder paththat
is too long to display then it ends with 'Path Not Found' - so theis
script
:
Set objFSO = CreateObject("Scripting.FileSystemObject")
objStartFolder = "\\server4\files"
Set objFolder = objFSO.GetFolder(objStartFolder)
Wscript.Echo objFolder.Path
Wscript.Echo
ShowSubfolders objFSO.GetFolder(objStartFolder)
Sub ShowSubFolders(Folder)
For Each Subfolder in Folder.SubFolders
Wscript.Echo Subfolder.Path
Set objFolder = objFSO.GetFolder(Subfolder.Path)
Wscript.Echo
ShowSubFolders Subfolder
Next
End Sub
If I add 'On Error Resume Nex't at the top, then it doesn't display the
error but the script just exits on the problem path again and won't go
any
further. I unfortunately don't have the means to change the path
structure
and make them smaller or use mapped drive etc. What I effectively need
is
the script to ignore any paths that cause a problem and just carry on
with
the next.
Is there any other way of getting round this?
Use a separate function to isolate the code overwhich the Resume Next
should
be active:-
Function GetFolderFromPath(Path)
On Error Resume Next
Set GetFolderFromPath = Nothing
Set GetFolderFromPath = objFSO.GetFolder(Path)
End Function
Now your function becomes:-
Sub ShowSubFolders(Folder)
For Each Subfolder in Folder.SubFolders
Wscript.Echo Subfolder.Path
If Not GetFolderFromPath(Subfolder.Path) Is Nothing Then
Wscript.Echo
ShowSubFolders Subfolder
End If
Next
End Sub
Of course you could just delete the line that assigns objFolder from
GetFolder since objFolder isn't being used. Why do you want to skip
these
folders? In what way is the result useful with missing information?
--
Anthony Jones - MVP ASP/ASP.NET
.
- References:
- Path not found error using FSO GetFolder
- From: J Talbot
- Re: Path not found error using FSO GetFolder
- From: Anthony Jones
- Re: Path not found error using FSO GetFolder
- From: J Talbot
- Path not found error using FSO GetFolder
- Prev by Date: Re: Path not found error using FSO GetFolder
- Next by Date: Re: Unlocking locked local accounts
- Previous by thread: Re: Path not found error using FSO GetFolder
- Next by thread: Re: Path not found error using FSO GetFolder
- Index(es):
Relevant Pages
|
Loading