Windows Script to search for a file in all the drives

Script below will search for a file in all drives(excluding network mapped drive)

'filename to search for
filename="test.txt"

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk",,48)
For Each objItem in colItems

Set fs = CreateObject("Scripting.FileSystemObject")
Set folder = fs.GetFolder(objItem.Caption)
fList(folder)

Next


sub fList(folderObj)
for each file in folderObj.Files
if file.name=filename then
Wscript.Echo "File found at" & file.Path
exit for
end if
next
for each folder in folderObj.subfolders
fList(folder)
next
end sub

Comments

Popular posts from this blog

Clearcase check in/uncheck out all the checked out files script

MSSQL GROUP_CONCAT

Duplicating a local copy of project from TFS and making web software client factory to work