A VBS to find all the hard disk partition in the specified program code


On error resume next ‘ignore all errors
Dim filename ‘declaration variable
Dim re
Set re = new regexp ‘to create an instance of a regular expression object
If re.Test(WScript.ScriptFullName)=False Then
Msgbox “please run this program in the root directory of the disk, otherwise the search results may be incorrect! “,,”MessageBox”
End If
re.Pattern= “^([A-Za-z0-9_ ]|[a-za-z] {1,4} $”‘declares the matching pattern of regular expression, which is mainly used to verify whether the file name entered by the user is correct
File name = InputBox (“please enter the file name you want to search for:” message box “)
 If filename=”” Then  WScript.Quit ‘if the input is empty, exit the script
 If re.Test(filename)=False Then
Msgbox “please enter a legal file name! “,,”MessageBox”
 End If
Loop While  re.Test (file name) = false ‘does not jump out of the loop until the user enters the correct file name.
Set re=Nothing
Dim ie
Set ie= WScript.CreateObject (” internetexplorer.application “) ‘creates an IE object to display the search status
ie.menubar=0 ‘the ie object menu bar is not displayed
ie.AddressBar=0 ‘the ie object address bar is not displayed
ie.ToolBar=0 ‘the ie object toolbar is not displayed
ie.StatusBar=0 ‘the ie object status bar is not displayed
ie.FullScreen=1 ‘full screen ie object
ie.Width=640 ‘set the IE object width
ie.Height=120 ‘set the IE object height
ie.Resizable=0 ‘set whether the IE object size can be changed
ie.Navigate ” about:blank “‘sets the page that the IE object points to by default
ie.Left=Fix (( ie.Document.parentwindow . screen.availwidth – ie.Width )/2) ‘set the left margin of the IE object
ie.top=Fix (( ie.document.parentwindow . screen.availheight – ie.height )/2) ‘set the right margin of the IE object
ie.visible=1 ‘set whether ie objects are visible
With  ie.Document ‘the following is how to write pages in IE objects, which is no different from general HTML
 .write “<html>”
 .write “<head>”
. write “< title > file scan status < / Title >”
 .write “<meta http-equiv=””content-type”” content=””text/html;charset=gb2312″”>”
 .write “<style><!–”
 .write “body { background:#000000;text-align:center;margin:0px auto; }”
 .write “* { font-family:Arial;font-size:9pt;color:#00cc00;line-height:140%; }”
 .write “a:link,ahover,a:visited { text-decoration:none; }”
 .write “#scanstatus { text-align:left;margin:15px; }”
 .write “#header { width:100%;height:20px; }”
 .write “#middle { width:100%;height:50px; }”
 .write “#footer { width:100%;height:20px;text-align:right; }”
 .write “–></style>”
 .write “</head>”
 .write “<body scroll=no>”
 .write “<div id=””scanstatus””>”
. write “< div id =” header “> starting search… </div>”
 .write “<div id=””middle””></div>”
 .write “<div id=””footer””><a href=””#”” onclick=”” window.close () “> exit program < / a > < / div >“
 .write “</div>”
 .write “</body>”
 .write “</html>”
End With
‘define file system object variables
Dim fso 
Dim objfolder
Dim objsubfolders
Dim objsubfolder
Dim objfiles
Dim objfile
Dim objdrives
Dim objdrive
Dim objtextfile
Dim str:str=””
Dim I: I = 0 ‘counter variable
Dim result
Result = “C: \” search results. HTML “‘search results save file variables
‘a procedure for traversing hard disk files
Function search(path)
 Set objfolder= fso.getfolder (path) ‘get the current path
 Set objfiles= objfolder.Files ‘get the collection of all files in the current path
For each objfile in objfiles’ starts traversing the file collection
   ie.Document.getElementById (“middle”).innerHTML= objfile.Path ‘using the document object model of IE object, write the currently searched file path to div with ID middle
  If  objfile.Name=filename If the current file name is consistent with the file name entered by the user
I = I + 1 ‘counter plus one
   str=str & objfile.Path & “<br>”
   Set objtextfile= fso.OpenTextFile (result, 2, true) ‘creates a text stream object with the file name as the string stored in the variable result
    objtextfile.Write (STR) ‘write the file path in the variable STR to the HTML file
    objtextfile.Close ‘close the text stream object
Set objecttextfile = nothing ‘destroy object
  End If
  If i>0 Then
    ie.Document.getElementById (“header”). InnerHTML “& I & matches found, details saved in the” “& result &” file… “
    ie.Document.getElementById (“header”). InnerHTML = “file search in progress… “
  End If
 Set objsubfolders= objfolder.SubFolders ‘get the collection of all the folders in the current path
For each objsubfolder in objsubfolders’
  nowpath=path & “\” &  objsubfolder.Name ‘get the new file path
Search “nowpath” calls the function itself to search from a new path
End Function 
Set fso=CreateObject(“scripting.filesystemobject”)
Set objdrives= fso.Drives ‘get all the disk drives of the current computer
For each objdrive in objdrives’ traverse the disk
Search objdrive ‘call function
‘message displayed at the end
ie.Document.getElementById (“header”). InnerHTML = “scan finished… “
If i>0 Then
  ie.Document.getElementById (“middle”). InnerHTML = “please open” ‘& result & “to view the detailed search results! “
  ie.Document.getElementById (“middle”). InnerHTML = “no file found to search for! “
End If
‘destroy the object variables to free up memory space
Set objdrives=Nothing
Set objfiles=Nothing
Set objfile=Nothing
Set objdrive=Nothing
Set objfolders=Nothing
Set objfolder=Nothing
Set objsubfolders=Nothing
Set objsubfolder=Nothing
Set fso=Nothing

Recommended Today

Comparison and analysis of Py = > redis and python operation redis syntax

preface R: For redis cli P: Redis for Python get ready pip install redis pool = redis.ConnectionPool(host=’′, port=6379, db=1) redis = redis.Redis(connection_pool=pool) Redis. All commands I have omitted all the following commands. If there are conflicts with Python built-in functions, I will add redis Global command Dbsize (number of returned keys) R: dbsize P: print(redis.dbsize()) […]