用asp实现的代码批量修改程序

是因工作需要做的一个批量修改代码的小东西,拿出来与大家分享
目前可以处理的文件类型:.asp .inc .htm .html 具体类型可自行修改添加

程序实现的功能:将源目录下的文件批量修改后存到目的目录下
用它稍做修改可以实现很多东西噢!

别的不说了,代码里面都写的很清楚了

 1   
 2Server.ScriptTimeOut = 500 '脚本超时时间 
 3
 4'// +---------------------------------------------------------------------------+   
 5'// | 批量修改函数 |   
 6'// | ------------------------------------------------------------------------- |   
 7'// | 属性:path_from 源文件目录 path_to 目标文件工作目录 |   
 8'// | ------------------------------------------------------------------------- |   
 9'// | 返回值:无 |   
10'// | ------------------------------------------------------------------------- |   
11'// | 程序流程:...... |   
12'// | ------------------------------------------------------------------------- |   
13'// | 编写者:WYC; 编写时间: 2004-03-08; |   
14'// +---------------------------------------------------------------------------+   
15Sub midfile(path_from, path_to)   
16list_from = path_from '储存当前源工作目录   
17list_to = path_to '储存当前目标工作目录   
18Set fso = CreateObject("Scripting.FileSystemObject")   
19Set Fold = fso.GetFolder(list_from) '获取Folder对象   
20Set fc = Fold.Files '获取文件记录集   
21Set mm = Fold.SubFolders '获取目录记录集   
22For Each f2 in mm   
23set objfile = server.createobject("scripting.filesystemobject")   
24objfile.CreateFolder(path_to & "\" & f2.name) '创建目录   
25midfile path_from & "\" & f2.name, path_to & "\" & f2.name '递归调用   
26response.write path_to & "\" & f2.name & " 完毕!

<br/>

 1"   
 2Next   
 3For Each f1 in fc   
 4file_from = list_from & "\" & f1.name '生成文件地址(源)   
 5file_to = list_to & "\" & f1.name '生成文件地址(到)   
 6fileExt = lcase(right(f1.name,4)) '获取文件类型   
 7If fileExt=".asp" or fileExt=".inc" or fileExt=".htm" or fileExt="html" Then '具体类型可自行修改添加   
 8set objfile = server.createobject("scripting.filesystemobject") '定义一个服务器组件(读取源文件)   
 9set out = objfile.opentextfile(file_from, 1, false, false)   
10content = out.readall '读取数据   
11out.close 
12
13'// +---------------------------------------------------+   
14'// | 文件内容处理模块(主要,其他都是文件操作) |   
15Set regEx = New RegExp   
16regEx.Pattern = "(\>\s*\n)"   
17regEx.Global = true '设置全部匹配模式   
18content = regEx.Replace(content, ">") '替换掉回车符   
19content = Replace(content, " ", "") '作tab替换   
20'// +---------------------------------------------------+ 
21
22set objfile = server.createobject("scripting.filesystemobject") '定义一个服务器组件(写入目标文件)   
23set outt = objfile.createtextfile(file_to,TRUE,FALSE)   
24outt.write(content) '写入数据   
25outt.close   
26else '否则直接复制文件   
27Set fso = CreateObject("Scripting.FileSystemObject")   
28fso.CopyFile file_from, file_to   
29End If   
30Next   
31End Sub 
32
33midfile Server.mappath("temp/aaa"), Server.mappath("temp/bbb") '调用示例 源目录temp/aaa 处理后存到temp/bbb   
34'源目录 目的目录(必须是已经存在的目录)   

manyou(他山之石) 敬上

Published At
Categories with Web编程
Tagged with
comments powered by Disqus