/build/static/layout/Breadcrumb_cap_w.png

Search folders for file?

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

Answers (4)

Posted by: aogilmor 19 years ago
9th Degree Black Belt
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.
Posted by: WiseUser 19 years ago
Fourth Degree Brown Belt
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
Posted by: Naffcat 19 years ago
Senior Purple Belt
0
This is perfect, nice and simple, many thanks!
Posted by: Naffcat 19 years ago
Senior Purple Belt
0
I totally agree - it seems to have got worse!
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

View more:

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ