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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find files on a system

Status
Not open for further replies.

mindone

Programmer
Feb 14, 2005
3
0
0
DE
hi,

i want to search for a file (if it exists) on a complete system (means: all drives should be searched).

can anybody tell me how to do this?

thanks in advance.

matthias
 
CreateObject("Shell.Application").FindFiles
If you want more control, consider the FileSystemObject (aka fso).
A search in this forum for search files returns hundreth of hits ...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
try this:

Code:
Set FSO = CreateObject("Scripting.FileSystemObject")
Set WshShell = WScript.CreateObject("WScript.Shell")

objextension = ucase(inputbox("Find What File?","Find"))


if objextension = "" then
	BtnCode = WshShell.Popup("You either hit CANCEL or left the text box blank." & vbcrlf & vbcrlf & vbtab & "      FIND 

WILL NOW QUIT!",5,"Ending...")
	WScript.Quit
end if

DRIVES ' calls the drive function

SubFolders FSO.GetFolder(DRVS & CHR(92)) 'calls the sub routine


' this sub is used to get the folder 

Sub SubFolders(objDirectory)
	Dim MoreFolders, TempFolder
	ListFiles objDirectory 	' calls the file sub routine	
	Set MoreFolders = objDirectory.SubFolders
	For Each TempFolder In MoreFolders
		SubFolders TempFolder
	Next
End Sub

' this sub is used to look at the files

Sub ListFiles(objDirectory)
	Dim TheFiles
	
	Set TheFiles = objDirectory.Files
	For Each objFile in TheFiles
		strExt = ucase(fso.GetFileName(objFile.Path))
			'msgbox strext & " " & objextension
        		If (strExt = objextension) Then
					BtnCode = WshShell.Popup(objFile.Path,5)
			End If
	Next
End Sub

' GETS THE FIXED DISK DRIVE LETTERS

Function DRIVES()
	
	dim oFS,collDrv
		
	set oFS=CreateObject("Scripting.FileSystemObject")
	set collDrv=oFS.Drives
	
	for each drv in collDrv
		if drv.DriveType=2 then 'check fixed drives only
			SubFolders oFS.GetFolder(DRV & CHR(92))
		end if
	next
	
End Function
'
MsgBox("All Done!")
WScript.Quit
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top