VB icon

Windows 10: Find any File of Any Type on Any Drive in Any Directory

Email
Submitted on: 6/24/2020 1:38:49 PM
By: A_X_O 
Level: Beginner
User Rating: Unrated
Compatibility: VbScript (browser/client side)
Views: 148
 
     

Find Any File of Any Type on Any Drive in Any Directory.


Find Lost Files, Anywhere on the System. Using File Type Or Part Name 

Enter the File Name or any part of the File Name to "Search For" Or if that information is not known, Enter the File Type. 
A "SearchResults.txt"  file will be created on the Desktop,  with the relevant results listed in it.
As this process is likely to be a lengthy one, Open Task-Manager and Monitor the Windows Scripting Host Process. You can end it at anytime.



 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: Windows 10: Find any File of Any Type on Any Drive in Any Directory
' Description:<br>
<p>
<b>Find Any File of Any Type on Any Drive in Any Directory.</b>
</p>
<hr>
<p>
<u><b>Find Lost Files, Anywhere on the System. Using File Type Or Part Name </b></u><br><br>
Enter the File Name or any part of the File Name to "Search For" Or if that information is not known, Enter the File Type. <br>
A "SearchResults.txt"  file will be created on the Desktop, 
with the relevant results listed in it.<br>
As this process is likely to be a lengthy one, Open Task-Manager and Monitor the Windows Scripting Host Process. You can end it at anytime.</p>
' By: A_X_O
'**************************************

'
'-------------------------------------------------------------------------------'
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++'
'		Demonstration: Windows 10, Search All Drives & Folders 		'
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++'
'										'
'	Purpose		: Find Any File on Any Drive in Any Directory		'
'	-----------------------------------------------------------------------	'
'	Creation Date	: 23/06/2020 [dd/mm/yyyy]				'
'	Version		: 1:0							'
'	Designer	: Fabian						'
'										'
'###############################################################################'
'			MODIFICATION HISTORY					'
'-------------------------------------------------------------------------------'
'										'
'	Version		: 1:0	23/06/2020	Create the Sample		'
'										'
'-------------------------------------------------------------------------------'		
'
Public Const ForReading = 1
Public Const ForWriting = 2
Public Const ForAppending = 8
Public Const LogFileName = "\SearchResults.txt"
'
Public Const QuestionText = "Do you know part of the file name ?"
Public Const QuestionTitle = "Known File Details"
'
Public Const ExtSrchPromptTxt = "What is the Extension of the file you've lost ?"
Public Const ExtSrchTitleTxt = "Search Entire System"
Public Const ExtSrchDefaultTxt = "doc"
Public Const NameSrchPromptTxt = "Enter part or all of the Name of the File you've lost ?"
Public Const NameSrchTitleTxt = "Search Entire System"
Public Const NameSrchDefaultTxt = "MyLostFile"
'
Public Const ObjFullPath = "Full System Path:"
Public Const ObjFullName = "System Name:"
'
Public Const ObjCreateDate = "Created On:"
Public Const ObjSizeMb = "Size(Mbs)"
'
Dim FSO
Dim WshShell
'
Dim LogFile
Dim DriveCollection
Dim Drive
'
Dim NameRetVal
Dim ExtRetVal
Dim SearchQuestion
Dim SearchName
Dim SearchExt
Dim ObjectName
Dim ObjectType
'
Dim ShrtPath
Dim File
Dim Files
Dim Path
Dim StrMyDesktop
'
Set FSO = CreateObject("Scripting.FileSystemObject")
Set WshShell = WScript.CreateObject("WScript.Shell")
'
	StrMyDesktop = WshShell.SpecialFolders("Desktop")
'
	SearchQuestion = MsgBox((QuestionText), _
			vbApplicationModal + vbExclamation + vbYesNoCancel, (QuestionTitle))
'
Select Case SearchQuestion
'
Case vbYes
'
	NameRetVal = InputBox((NameSrchPromptTxt), (NameSrchTitleTxt), (NameSrchDefaultTxt))
'
If NameRetVal <> VbNullString Then
'
	SearchName = NameRetVal
'
End If
'
Case vbNo
'
	ExtRetVal = InputBox((ExtSrchPromptTxt), (ExtSrchTitleTxt), (ExtSrchDefaultTxt))
'
If ExtRetVal <> VbNullString Then
'
	SearchExt = ExtRetVal
'
End If
'
End Select
'
Set LogFile = FSO.CreateTextFile(StrMyDesktop & LogFileName, True)
'
Set DriveCollection = FSO.Drives
'
For Each Drive in DriveCollection
'
If Drive.IsReady Then 
'
Call Search(Drive.DriveLetter & ":\")
'
End If
'
Next
'
Public Function Search(Path)
On Error Resume Next 
'
Set Folder = FSO.GetFolder(Path)
'
Set Files = Folder.Files 
'
For Each File in Files 
'
Set ObjectPath = FSO.GetFile(File.Path)
'
If SearchName <> VbNullString Then
'
	ObjectName = FSO.GetFileName(File.Path)
'
If Instr(1, (LCase(ObjectName)), SearchName, 1) Then
'
Set LogFile = FSO.OpenTextFile((StrMyDesktop & LogFileName), ForAppending)
'
 LogFile.Write VbCrLf & ObjFullPath & VbTab & (ObjectPath.Path) & VbCrLf & _
			ObjFullName & VbTab & VbTab & Trim(ObjectName) & VbCrLf & ObjCreateDate & _
			VbTab & VbTab & ObjectPath.DateCreated & VbCrLf & String(100,"-") & VbCrLf
'
End If
'
Else
'
	ObjectType = FSO.GetExtensionName(File.Path)
'
If SearchExt = ObjectType Then
'
Set LogFile = FSO.OpenTextFile((StrMyDesktop & LogFileName), ForAppending)
'
 LogFile.Write VbCrLf & ObjFullPath & VbTab & (ObjectPath.Path) & VbCrLf & _
			ObjFullName & VbTab & VbTab & Trim(ObjectName) & VbCrLf & ObjCreateDate & _
			VbTab & VbTab & ObjectPath.DateCreated & VbCrLf & String(100,"-") & VbCrLf
'
End If
'
End If
'
Next 
'
Set SubFolders = Folder.SubFolders 
'
For Each SubFolder In SubFolders
'
Call Search(SubFolder.Path)
'
Next
'
End Function


Other 19 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.