How to use the FSO to search hard disk files _fso topics

Source: Internet
Author: User


<% @LANGUAGE = "VBSCRIPT" codepage= "936"%>
<%
Dim St
St=timer ()
'*************************************************************
' ************* search hard disk files for class Searchfile *************
' ************* Call Method: *************
' *************set newsearch=new searchfile ' statement *************
' *************newsearch. Folder= "F:+e:" ' Incoming search source *************
' *************newsearch.keyword= ' assembly ' keyword *************
' *************newsearch. Search ' Start searching *************
' *************set newsearch=nothing ' end *************
'*************************************************************
Class Searchfile
Dim Folders ' Pass in absolute path, multiple paths using + number connection, no spaces
Dim keyword ' incoming keyword
Dim objFSO ' Defines global variables
Dim Counter ' Defines global variables, number of search results
' ***************** initialization **************************************
Private Sub Class_Initialize
Set objfso=server.createobject ("Scripting.FileSystemObject")
Counter=0 ' Initialization counter
End Sub
'************************************************************
Private Sub Class_Terminate
Set objfso=nothing
End Sub
' ************** public members, calling methods ***************************
Function Search
Folders=split (Folders, "+") ' converts to arrays
Keyword=trim (keyword) ' Remove space before and after
If keyword= "" Then
Response.Write ("<font color= ' red ' > keyword cannot be empty </font><br/>")
Exit Function
End If
' Determine if illegal characters are included
FLAG=INSTR (keyword, "") or InStr (keyword, "/")
Flag=flag or InStr (keyword, ":")
Flag=flag or InStr (keyword, "|")
Flag=flag or InStr (keyword, "&")

The IF flag then ' keyword cannot contain/:|&
Response.Write ("<font color= ' red ' > keyword cannot contain/:|&</font><br/>")
Exit Function ' Exits if included with this
End If
' Multi-Path search
Dim i
For i=0 to UBound (Folders)
Call Getallfile (Folders (i)) ' calls a circular recursive function
Next
Response.Write ("Search to <font color= ' red ' >" &Counter& "</font> results")
End Function
' *************** Calendar files and folders ******************************
Private Function getallfile (Folder)
Dim objfd,objfs,objff
Set Objfd=objfso.getfolder (Folder)
Set objfs=objfd.subfolders
Set Objff=objfd.files
' Calendar subfolders
Dim strfdname ' Declares subfolder name
' ********* Calendar subfolders
On Error Resume Next
For each onedir in OBJFS
Strfdname=onedir.name
' System folders are not listed in the calendar
If strfdname<> "Config.msi" EQV strfdname<> "recycled" EQV strfdname<> "RECYCLER" EQV > "System Volume Information" Then
sfn=folder& "" &strfdname ' absolute path
Call Getallfile (SFN) ' calls recursion
End If
Next
Dim strflname
' ********** Calendar file ********
For each onefile in OBJFF
Strflname=onefile.name
' Desktop.ini and folder.htt out of range
If strflname<> "Desktop.ini" EQV strflname<> "Folder.htt" Then
fn=folder& "" &strflname
Counter=counter+coloron (FN)
End If
Next
'***************************
' Close each object instance
Set objfd=nothing
Set objfs=nothing
Set objff=nothing
End Function
' ********************* generation matching pattern ***********************************
Private Function createpattern (keyword)
Createpattern=keyword
Createpattern=replace (Createpattern, ".", ".")
Createpattern=replace (Createpattern, "+", "+")
Createpattern=replace (Createpattern, "(") (")
Createpattern=replace (Createpattern, ")", ")")
Createpattern=replace (Createpattern, "[", "[")
Createpattern=replace (Createpattern, "]", "]")
Createpattern=replace (Createpattern, "{", "{")
Createpattern=replace (Createpattern, "}", "}")
Createpattern=replace (Createpattern, "*", "[^\/]*") ' * # match
Createpattern=replace (Createpattern, "?", "[^\/]{1}") ' # match
Createpattern= "(" &CreatePattern& ") +" ' overall match
End Function
' ************************** search and color the keywords *************************
Private Function Coloron (FileName)
Dim Objreg
Set objreg=new REGEXP
Objreg.pattern=createpattern (keyword)
Objreg.ignorecase=true
Objreg.global=true
Retval=objreg.test (FileName) ' Conduct search test, paint and output if passed
If RetVal Then
Output=objreg.replace (FileName, "<font color= ' #FF0000 ' >$1</font>") ' Sets the display color of the keyword
' *************************** This section can modify the output according to the need ************************************
output= "<a href= ' >" &OutPut& "</a><br/>"
Response.Write (output) ' output matches the result
' ************************************* modifiable partial end **************************************
Coloron=1 ' Number of Add counters
Else
Coloron=0
End If
Set objreg=nothing
End Function
End Class
' ************************ End Class searchfile**********************
%>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<title>www.csdn.com.cn</title>

<body>
<form name= "Form1" method= "Post" action= "<% =request.servervariables (" Path_info ")%>" >
Keywords:
<input name= "keyword" type= "text" id= "keyword" >
<input type= "Submit" name= "submit" value= "Search" >
<a href= "help.htm" target= "_blank" > Advanced Search Help </a>
</form>
<%
Dim keyword
Keyword=request.form ("keyword")
If keyword<> "" Then
Set newsearch=new Searchfile
NewSearch. folders= "E:media+f:"
Newsearch.keyword=keyword
NewSearch. Search
Set newsearch=nothing
Response. Write ("<br/> Time Consuming:" & (Timer ()-st) *1000& "milliseconds")
End If

%>
</body>




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.