ASP-Implemented Code batch modification program, FSO related
is because the job needs to do a lot of code to modify the small things, take out to share with you
File types that can be processed at this time:. ASP. inc. HTM. HTML specific types can be modified by adding
program implementation of the function: the source directory of the file batch modified to save to the destination directory
It can be done a lot of things with a little modification.
Nothing else to say, the code is written in very clear
<%
'// +---------------------------------------------------------------------------+
'// | Program name: His mountain stone code batch modifier v1.01 |
'// | The stone of his mountain all rights reserved, infringement must investigate! Reprint please specify the Copyright:) |
'// | ------------------------------------------------------------------------- |
'// | System: Win2000; Editor: EditPlus; Indent tool: Tab; Indent Length: 8; Font: XXFarEastFont-Arial (10pt); |
'// | ------------------------------------------------------------------------- |
'// | Created by: WYC; Date created: 2004-03-08; |
'// | Written by: WYC; Written time: 2004-03-08; |
'// +---------------------------------------------------------------------------+
Server.ScriptTimeout = 500 ' script timeout
'// +---------------------------------------------------------------------------+
'// | Batch modification Function |
'// | ------------------------------------------------------------------------- |
'// | Properties: Path_from source file directory path_to target file working directory |
'// | ------------------------------------------------------------------------- |
'// | return Value: none |
'// | ------------------------------------------------------------------------- |
'// | Program Flow: ... |
'// | ------------------------------------------------------------------------- |
'// | Written by: WYC; Written time: 2004-03-08; |
'// +---------------------------------------------------------------------------+
Sub midfile (Path_from, path_to)
List_from = Path_from ' stores current source working directory
list_to = Path_to ' stores current target working directory
Set fso = CreateObject ("Scripting.FileSystemObject")
Set Fold = fso. GetFolder (list_from) ' Get Folder object
Set fc = Fold.files ' Get file recordset
set mm = Fold.subfolders ' Get catalog recordset
For each F2 in mm
Set objfile = Server.CreateObject ("Scripting.FileSystemObject")
objFILE. CreateFolder (Path_to & "& f2.name)" Create directory
Midfile Path_from & "\" & F2.name, Path_to & "\ & F2.name ' recursive call
Response.Write path_to & "& F2.name &" Complete! <br> "
Next
For each F1 in FC
File_from = list_from & "\" & f1.name ' generate file address (source)
file_to = list_to & "\" & f1.name ' generate file address (to)
Fileext = LCase (Right (f1.name,4)) ' Get file type
If fileext= ". asp" or "Fileext=". Inc "or fileext=". htm "or fileext=" html "Then" specific types can be modified by themselves
Set objfile = Server.CreateObject ("Scripting.FileSystemObject") ' defines a server component (reads the source file)
set out = Objfile.opentextfile (File_from, 1, false, False)
Content = Out.readall ' Read data
Out.close
'// +---------------------------------------------------+
'// | File content Processing module (main, other file operations) |
Set regEx = New RegExp
Regex.pattern = "(\>\s*\n)"
Regex.global = True ' Sets all match mode
Content = Regex.Replace (content, ">") ' Replace the return character
Content = Replace (content, "", "") "as tab replacement
'// +---------------------------------------------------+
Set objfile = Server.CreateObject ("Scripting.FileSystemObject") ' defines a server component (writes to the destination file)
Set Outt = Objfile.createtextfile (file_to,true,false)
Outt.write (content) ' Write data
Outt.close
Else ' Otherwise ' copy files directly
Set fso = CreateObject ("Scripting.FileSystemObject")
Fso. CopyFile File_from, file_to
End If
Next
End Sub
Midfile Server.MapPath ("Temp/aaa"), Server.MapPath ("temp/bbb") ' invokes the sample source directory TEMP/AAA processing to save to TEMP/BBB
' Source directory destination directory (must be a directory that already exists)
%>