Can anyone tell me where I can get a vbscript to search a folder and sub folder for a file? I've tried looking on MS script center but could find one.

Also are there any other places to download scripts from other the MS script center?
0 Comments   [ + ] Show Comments

Comments

Please log in to comment

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.

Answers

0
google groups should have something for ya.

HATE MSFT vbscript web site - all over the map. Used to be easy to find sample scripts, but no more.
Answered 02/03/2005 by: aogilmor
Ninth Degree Black Belt

Please log in to comment
0
Here's a very crude one I just wrote - it doesn't search for folders (only files), it only returns the first file that it finds, and it doesn't work on the root of a drive. But it should point you in the right direction...


Set oFso = CreateObject("Scripting.FileSystemObject")

Msgbox sFindFile("hosts", "c:\Windows", True)

Function sFindFile(sFile, sFolder, bRecurse)

Set oFolder = oFso.GetFolder(sFolder)

Set cFiles = oFolder.Files

For Each oFile in cFiles

If LCase(oFile.Name) = LCase(sFile) Then

sFindFile = oFile.Path : Exit Function

End If

Next

Set cSubFolders = oFolder.SubFolders

If bRecurse Then

For Each oSub in cSubFolders

sFindFile = sFindFile(sFile, oSub.Path, bRecurse)
If sFindFile <> "" Then Exit Function

Next

End If

End Function

Set oFso = Nothing
Answered 02/04/2005 by: WiseUser
Fourth Degree Brown Belt

Please log in to comment
0
This is perfect, nice and simple, many thanks!
Answered 02/04/2005 by: Naffcat
Senior Purple Belt

Please log in to comment
0
I totally agree - it seems to have got worse!
Answered 02/05/2005 by: Naffcat
Senior Purple Belt

Please log in to comment
Answer this question or Comment on this question for clarity