Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File Find using VBscripting

Status
Not open for further replies.

Janey66

IS-IT--Management
Jul 22, 2003
3
US
I'm looking for a quick way to find a file on a drive and have it spit out the directory of where the file is located. Any way I can do that?
 
Try this

Code:
dim filesys, folder, File
File = "c:\whatever.txt"
Set filesys = CreateObject("Scripting.FileSystemObject")
If filesys.FileExists (File) Then
folder = filesys.GetParentFolderName(File)
Wscript.Echo (folder)
Else
    Wscript.Echo "File does not exist"
End If
 
If you have excel you can use it's file search ability. Otherwise you can use the FileSystemObject to go through folders and files looking for your file. You could also use WMI and the CIM_DataFile class to search for your file (the more specific the better you'll be using this method).

dm4ever
--------------------------------------------------------------------------------
My approach to things: K.I.S.S - Keep It Simple Stupid
 
Which method are you referring to? You can get any of the three methods I mentioned to look in any folder and subfolders. The example stevio posted can be modified to go through the various folders and subfolders looking for your file if you don't know the exact path.

dm4ever
--------------------------------------------------------------------------------
My approach to things: K.I.S.S - Keep It Simple Stupid
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top