Re: Path not found error using FSO GetFolder



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
Hi

I'm using a script to get a list of folders (and subfolders) for a UNC
path
but I noticed that if the script tries to get hold of a subfolder path
that
is too long to display then it ends with 'Path Not Found' - so the
script
is
:


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








.



Relevant Pages

  • Re: CLean out all users Temp Dir Folder
    ... I've built the script you need with ScriptAhead a tool we have just ... ' Get Folders that match the following criteria: ... Sub AppendCollectionToArray ... GetSubFolders strFolderName ...
    (microsoft.public.windows.server.scripting)
  • Re: copy text files only from all subfolders within a folder to a
    ... My Script: ... Sub AllFolders (Folder) ... For Each SubFolder in Folder.Subfolders ... Sub CopyTextFiles (subFolder) ...
    (microsoft.public.scripting.vbscript)
  • Re: Path not found error using FSO GetFolder
    ... Sub ShowSubFolders ... For Each Subfolder in Folder.SubFolders 'Path Not Found error on this ... 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 ...
    (microsoft.public.scripting.vbscript)
  • Re: Count Files and Folders
    ... I hacked the script a little to also include the total number of folders, ... Sub CountSubfolderFiles ... CountSubfolderFiles Subfolder ...
    (microsoft.public.scripting.vbscript)
  • Re: Archive Message Folder Script by Jolly Roger
    ... inside each of those root folders is a multitude of sub folders. ... Now I have run the script a number of times and it makes it through ...
    (microsoft.public.mac.office.entourage)

Loading