Code batch modification programs implemented using asp, fso-related
This is a small batch code modification task for your work.
Currently, file types that can be processed:. asp. inc. htm. html can be modified and added by yourself.
Function implemented by the Program: Modify the files in the source directory in batches and save them to the target directory.
You can use it to slightly modify it to implement many things!
Nothing else. The code is clearly written.
<%
'// + ----------------------------------------------------------------------------- +
'// | Program name: Batch modifier v1.01 of others' stone codes |
'// | All rights reserved for the stone of another hill. infringement is required! Reprinted, please indicate copyright :) |
'// | ------------------------------------------------------------------------- |
'// | System: win2000; Editor: EditPlus; indent tool: Tab; indent length: 8; Font: 10( 10pt); |
'// | ------------------------------------------------------------------------- |
'// | Creator: WYC; Creation Time:; |
'// | Prepared by: WYC; written at:; |
'// + ----------------------------------------------------------------------------- +
Server. ScriptTimeOut = 500 'script timeout
'// + ----------------------------------------------------------------------------- +
'// | Modify functions in batches |
'// | ------------------------------------------------------------------------- |
'// | Attribute: path_from source file directory path_to target file working directory |
'// | ------------------------------------------------------------------------- |
'// | Return value: None |
'// | ------------------------------------------------------------------------- |
'// | Program process:... |
'// | ------------------------------------------------------------------------- |
'// | Prepared by: WYC; written at:; |
'// + ----------------------------------------------------------------------------- +
Sub midfile (path_from, path_to)
List_from = path_from 'stores the current source working directory
List_to = path_to 'stores the current target working directory
Set fso = CreateObject ("Scripting. FileSystemObject ")
Set Fold = fso. GetFolder (list_from) 'Get the Folder object
Set fc = Fold. Files 'get the file record Set
Set mm = Fold. SubFolders 'get the directory record Set
For Each f2 in mm
Set objfile = server. createobject ("scripting. filesystemobject ")
Objfile. CreateFolder (path_to & "\" & f2.name) 'to create a directory
Midfile path_from & "\" & f2.name, path_to & "\" & f2.name 'recursive call
Response. write path_to & "\" & f2.name & "finished! <Br>"
Next
For Each f1 in fc
File_from = list_from & "\" & f1.name 'generate the file address (source)
File_to = list_to & "\" & f1.name 'generate the file address ()
FileExt = lcase (right (f1.name, 4) 'get the file type
If fileExt = ". asp" or fileExt = ". inc" or fileExt = ". htm" or fileExt = "html" then', you can modify the type and add it as needed.
Set objfile = server. createobject ("scripting. filesystemobject") 'defines a server component (read 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 operations) |
Set regEx = New RegExp
RegEx. Pattern = "(\> \ s * \ n )"
RegEx. Global = true' set all matching Modes
Content = regEx. Replace (content, ">") 'replaces the carriage return.
Content = Replace (content, "", "") 'For tab replacement
'// + ----------------------------------------------------- +
Set objfile = server. createobject ("scripting. filesystemobject") 'defines a server component (written to the target file)
Set outt = objfile. createtextfile (file_to, TRUE, FALSE)
Outt. write (content) 'write Data
Outt. close
Else' otherwise, copy the file 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") 'Call the sample source directory temp/aaa for processing and save it to temp/bbb
'Destination directory of the source directory (must be an existing Directory)
%>