VBS finds the implementation code for the specified extension file in the hard disk partition _vbs

Source: Internet
Author: User
Tags regular expression save file

A very practical piece of code, used to drill down to the VBS, really good slightly.

Copy Code code as follows:

On error Resume Next ' ignores all errors
Dim filename ' declares variable
Dim RE
Set Re=new REGEXP ' establish a regular expression object instance
re.pattern= "^ ([a-z]|[ A-z]) +\:\\\w+\.vbs$ "
If Re. Test (wscript.scriptfullname) =false Then
MsgBox "Please run this program in the root directory of the disk, otherwise the search results may not be correct!" ",," MessageBox "
Wscript.Quit
End If
Re. pattern= "^ ([a-za-z0-9_]|[ ^\X00-\XFF]) +\. [A-za-z] {1,4}$ "' declares a matching pattern of regular expressions, primarily to verify that the file name entered by the user is correct
Todo
Filename=inputbox ("Please enter the filename you want to search for:", "MessageBox")
If Filename= "" Then wscript.quit "exit script if entered as null
If Re. Test (filename) =false Then
MsgBox "Please enter a valid filename!" ",," MessageBox "
End If
Loop while re. Test (filename) =false ' does not jump out of the loop until the user enters the correct filename.
Set re=nothing
Dim IE
Set Ie=wscript.createobject ("Internetexplorer.application") ' establishes IE object to display search status
Ie.menubar=0 ' does not show ie Object menu bar
Ie. Addressbar=0 ' Don't show IE object Address bar
Ie. Toolbar=0 ' Don't show ie object toolbar
Ie. Statusbar=0 ' does not show IE object status bar
Ie. Fullscreen=1 ' Full-screen IE objects
Ie. width=640 ' Set IE object width
Ie. Height=120 ' Set IE object height
Ie. Resizable=0 ' Set whether IE object size can be changed
Ie. Navigate "About:blank" set 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 IE object
Ie.top=fix ((ie.document.parentwindow.screen.availheight-ie.height)/2) ' Set the right margin of IE object
Ie.visible=1 ' Sets whether IE objects are visible
With IE. Document ' The following is written to a page in IE objects, no different from normal HTML
. Write ". Write ". 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 ". Write "<body scroll=no>"
. Write "<div id=" "Scanstatus" ">"
. Write "<div id=" header "> starting the Search program ... </div> "
. Write "<div id=" "Middle" "></div>"
. Write "<div id=" "Footer" "><a href=" "#" "Onclick=" "Window.close ()" "> Exit program </a></div>"
. Write "</div>"
. Write "</body>"
. Write "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= "E:\ search results. html" Search results Save file variables
' A process used to traverse hard disk files
Function Search (PATH)
Set objfolder=fso.getfolder (path) ' Get current path '
Set Objfiles=objfolder. Files ' gets all the file collections under the current path
For each objfile in Objfiles ' begins traversing the file collection
Ie. document.getElementById ("Middle"). Innerhtml=objfile. Path ' uses the Document object model of the IE object to write the file path of the current search to the div with ID middle
If objfile. Name=filename Then ' If the current file name is the same as 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 that is the string stored by the variable result
objTextFile. Write (str) ' writes the file path in variable str to an HTML file
objTextFile. Close ' closes the text stream object
Set objtextfile=nothing ' Destroy object
End If
If i>0 Then
Ie. document.getElementById ("header"). innerhtml= "Find & I &" matches, details have been saved in "" "& Result &" "File ... "
Else
Ie. document.getElementById ("header"). Innerhtml= "Performing a file search ... "
End If
Wscript.Sleep (20)
Next
Set Objsubfolders=objfolder. Subfolders ' Get a collection of all the folders under the current path
For each objsubfolder in Objsubfolders ' Traversal folder
Nowpath=path & "\" & Objsubfolder. Name ' Gets the new file path
Search Nowpath ' calls the function itself, starting with the new path
Next
End Function
Set fso=createobject ("Scripting.FileSystemObject")
Set Objdrives=fso. Drives ' Get all the disk drives on the current computer
For each objdrive in objdrives ' traversal disk
Search Objdrive ' Call function
Next
' The information displayed at the end
Ie. document.getElementById ("header"). Innerhtml= "Scan has ended ... "
If i>0 Then
Ie. document.getElementById ("Middle"). Innerhtml= "Please open" "& Result &" "To view detailed search results! "
Else
Ie. document.getElementById ("Middle"). Innerhtml= "did not find the file to search for!" "
End If
' Destroy object variables and 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.