' It's a little bit easier to change a small program on the web, which is a good search efficiency.
Copy Code code as follows:
On Error Resume Next
Dim KeyWord, Dirtotal, Timespend, Filetotal, Fso, outfile, Txtresult, Txtpath, spath
Const My_computer = &H11&
Const window_handle = 0
Const OPTIONS = 0
Set Objshell = CreateObject ("Shell.Application")
Set objfolder = Objshell.namespace (my_computer)
Set objFolderItem = objfolder.self
strpath = Objfolderitem.path
Set objfolder = Objshell.browseforfolder (Window_handle, "Select the folder you want to search:", options, strpath)
If Objfolder is nothing Then
MsgBox "You did not select any valid directory!"
Wscript.Quit
Else
Set objFolderItem = objfolder.self
spath = Objfolderitem.path
Txtpath=spath
Set Fso = WScript. CreateObject ("Scripting.FileSystemObject")
Filetotal = 0
Dirtotal = 0
' spath = Left (Wscript.scriptfullname,len (wscript.scriptfullname)-len (WScript.ScriptName))
' Txtpath = Trim (InputBox ("Your chosen directory is" &spath, "File Search", spath))
KeyWord = LCase (InputBox ("Please enter the search key point cancel will get the directory list:", "File Search", "MP3"))
Set outfile = Fso.createtextfile (spath & "\searchresult.txt")
Outfile.writeline "Start search ..."
Outfile.writeline "Starting directory:" & Txtpath
Timespend = Timer
Myfind Txtpath
Timespend = Round (timer-timespend,2)
Txtresult = "Search Complete!" & vbCrLf & to find Files: "& Filetotal &". "& vbCrLf &" Search directory: "& Dirtotal ; "& VbCrLf &" When: "& Timespend &" seconds. "
Outfile.write Txtresult
MsgBox Txtresult & "Results saved in" &spath & \searchresult.txt "
Outfile.close
Set outfile = Nothing
Set Fso = Nothing
Sub Myfind (ByVal thepath)
Dim FSO, MyFolder, MyFile, CurFolder
Set FSO = WScript. CreateObject ("Scripting.FileSystemObject")
Set curfolders = Fso.getfolder (thepath)
Dirtotal = dirtotal + 1
If curFolders.Files.Count > 0 Then
For each myFile in Curfolders.files
If InStr (1, LCase (myfile.name), KeyWord) > 0 Then
Outfile.writeline Formatpath (thepath) & "\" & myFile.Name
Filetotal = filetotal + 1
End If
Next
End If
If curFolders.subfolders.Count > 0 Then
For each myFolder in Curfolders.subfolders
Myfind Formatpath (thepath) & "\" & Myfolder.name
Next
End If
End Sub
Function Formatpath (ByVal thepath)
Thepath = Trim (thepath)
Formatpath = Thepath
If Right (thepath, 1) = "\" Then Formatpath = Mid (Thepath, 1, Len (thepath)-1)
End Function
End If
=======================================================================
Attachments: About Open Directories:
Private Const csidl_desktop = &h0 ' <desktop>
Private Const csidl_internet = &h1 ' INTERNET Explorer (icon on desktop)
Private Const csidl_programs = &h2 ' Start menu\programs
Private Const csidl_controls = &h3 ' My Computer\control Panel
Private Const csidl_printers = &h4 ' My computer\printers
Private Const csidl_personal = &h5 ' My Documents
Private Const csidl_favorites = &h6 ' <user name>\favorites
Private Const csidl_startup = &h7 ' Start Menu\Programs\Startup
Private Const csidl_recent = &h8 ' <user name>\recent
Private Const csidl_sendto = &h9 ' <user name>\sendto
Private Const csidl_bitbucket = &ha ' <desktop>\recycle Bin
Private Const csidl_startmenu = &hb ' <user name>\start Menu
Private Const csidl_mydocuments = &HC ' logical ' my Documents ' desktop icon
Private Const csidl_mymusic = &hd ' My Music ' folder
Private Const csidl_myvideo = &he ' My Videos ' folder
Private Const csidl_desktopdirectory = &h10 ' <user name>\desktop
Private Const csidl_drives = &h11 ' My Computer
Private Const csidl_network = &h12 ' Network Neighborhood (My network Places)
Private Const csidl_nethood = &h13 ' <user name>\nethood
Private Const csidl_fonts = &h14 ' windows\fonts
Private Const csidl_templates = &h15
Private Const csidl_common_startmenu = &h16 ' All Users\Start Menu
Private Const csidl_common_programs = &h17 ' All Users\Start Menu\Programs
Private Const csidl_common_startup = &h18 ' All Users\startup
Private Const csidl_common_desktopdirectory = &h19 ' All Users\Desktop
Private Const csidl_appdata = &h1a ' <user name>\application Data
Private Const csidl_printhood = &h1b ' <user name>\printhood
Private Const csidl_local_appdata = &h1c ' <user name>\local Settings\applicaiton Data (non roaming)
Private Const csidl_altstartup = &h1d ' Non localized startup
Private Const csidl_common_altstartup = &h1e ' Non localized COMMON startup
Private Const csidl_common_favorites = &h1f
Private Const csidl_internet_cache = &h20 ' temporary INTERNET FILES
Private Const csidl_cookies = &h21
Private Const csidl_history = &h22
Private Const csidl_common_appdata = &h23 ' All Users\Application Data
Private Const csidl_windows = &h24 ' GetWindowsDirectory ()
Private Const csidl_system = &h25 ' GetSystemDirectory ()
Private Const csidl_program_files = &h26 ' C:\Program FILES
Private Const csidl_mypictures = &h27 ' C:\Program files\my Pictures
Private Const csidl_profile = &h28 ' userprofile
Private Const csidl_systemx86 = &h29 ' x86 system directory on RISC
Private Const csidl_program_filesx86 = &H2A ' x86 C:\Program Files on RISC
Private Const Csidl_program_files_common = &h2b ' C:\Program Files\Common
Private Const csidl_program_files_commonx86 = &H2C ' x86 Program Files\Common on RISC
Private Const csidl_common_templates = &h2d ' All Users\templates_
Private Const csidl_common_documents = &h2e ' All users\documents
Private Const csidl_common_admintools = &h2f ' All Users\Start menu\programs\administrative Tools
Private Const csidl_admintools = &h30 ' <user name>\start menu\programs\administrative Tools
Private Const csidl_connections = &h31 ' Network and dial-up connections
Private Const csidl_common_music = &h35 ' All Users\My MUSIC
Private Const csidl_common_pictures = &h36 ' All Users\My PICTURES
Private Const csidl_common_video = &h37 ' All Users\My
Private Const csidl_resources = &h38 ' Resource direcotry
Private Const csidl_resources_localized = &h39 ' localized Resource direcotry
Private Const csidl_common_oem_links = &h3a ' LINKS to all Users OEM specific apps
Private Const Csidl_cdburn_area = &h3b ' userprofile\local Settings\Application Data\Microsoft\CD Burning
Private Const csidl_computersnearme = &h3d ' Computers Near Me (computered from Workgroup membership)
Private Const csidl_flag_create = &h8000 ' combine with Csidl_ value to force folder creation in SHGetFolderPath ()
Private Const csidl_flag_dont_verify = &h4000 ' combine with csidl_ value to return a unverified folder path
Private Const Csidl_flag_no_alias = &h1000 ' combine with csidl_ value to insure Non-alias the versions
Private Const csidl_flag_per_user_init = &h800 ' combine with csidl_ value to indicate Per-user INIT (eg. upgrade)
Private Const csidl_flag_mask = &hff00 ' MASK for all possible FLAG values