设为首页   加入最爱           最新更新:全方位英文文章资料库
 
资料坊搜索: 标题 全文     
用asp实现的代码批量修改程序,fso相关
   首页>>YesizeCOM>>电脑技能坊>>ASP>>正文       
 
广告招租,e-mail:yesize@hotmail.com

广告招租,e-mail:yesize@hotmail.com


用asp实现的代码批量修改程序,fso相关

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

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

别的不说了,代码里面都写的很清楚了
<%
// +---------------------------------------------------------------------------+
// | 程序名称: 他山之石代码批量修改器 v1.01 |
// | 他山之石版权所有,侵权必究!转载请注明版权:) |
// | ------------------------------------------------------------------------- |
// | 系统:win2000; 编辑器:EditPlus; 缩进工具:Tab; 缩进长度:8; 字体:宋体(10pt); |
// | ------------------------------------------------------------------------- |
// | 创建者: WYC; 创建时间: 2004-03-08; |
// | 编写者: WYC; 编写时间: 2004-03-08; |
// +---------------------------------------------------------------------------+

Server.ScriptTimeOut = 500 脚本超时时间

// +---------------------------------------------------------------------------+
// | 批量修改函数 |
// | ------------------------------------------------------------------------- |
// | 属性:path_from 源文件目录 path_to 目标文件工作目录 |
// | ------------------------------------------------------------------------- |
// | 返回值:无 |
// | ------------------------------------------------------------------------- |
// | 程序流程:...... |
// | ------------------------------------------------------------------------- |
// | 编写者:WYC; 编写时间: 2004-03-08; |
// +---------------------------------------------------------------------------+
Sub midfile(path_from, path_to)
list_from = path_from 储存当前源工作目录
list_to = path_to 储存当前目标工作目录
Set fso = CreateObject("Scripting.FileSystemObject")
Set Fold = fso.GetFolder(list_from) 获取Folder对象
Set fc = Fold.Files 获取文件记录集
Set mm = Fold.SubFolders 获取目录记录集
For Each f2 in mm
set objfile = server.createobject("scripting.filesystemobject")
objfile.CreateFolder(path_to & "\" & f2.name) 创建目录
midfile path_from & "\" & f2.name, path_to & "\" & f2.name 递归调用
response.write path_to & "\" & f2.name & " 完毕!<br>"
Next
For Each f1 in fc
file_from = list_from & "\" & f1.name 生成文件地址(源)
file_to = list_to & "\" & f1.name 生成文件地址(到)
fileExt = lcase(right(f1.name,4)) 获取文件类型
If fileExt=".asp" or fileExt=".inc" or fileExt=".htm" or fileExt="html" Then 具体类型可自行修改添加
set objfile = server.createobject("scripting.filesystemobject") 定义一个服务器组件(读取源文件)
set out = objfile.opentextfile(file_from, 1, false, false)
content = out.readall 读取数据
out.close

// +---------------------------------------------------+
// | 文件内容处理模块(主要,其他都是文件操作) |
Set regEx = New RegExp
regEx.Pattern = "(\>\s*\n)"
regEx.Global = true 设置全部匹配模式
content = regEx.Replace(content, ">") 替换掉回车符
content = Replace(content, " ", "") 作tab替换
// +---------------------------------------------------+

set objfile = server.createobject("scripting.filesystemobject") 定义一个服务器组件(写入目标文件)
set outt = objfile.createtextfile(file_to,TRUE,FALSE)
outt.write(content) 写入数据
outt.close
else 否则直接复制文件
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") 调用示例 源目录temp/aaa 处理后存到temp/bbb
源目录 目的目录(必须是已经存在的目录)
%>


上一篇:在ASP中使用FSO组件生成HTML页面 下一篇:fso实例

版权说明:作品来源于网上,版权归作者所有,如果无意中侵犯了您的版权,请来信告知,本站将在3个工作日内删除。yesize@hotmail.com
  热门小游戏分类 
射击小游戏 连连看小游戏
台球小游戏 成人小游戏
CS小游戏 化妆小游戏
赛车小游戏 休闲小游戏
篮球小游戏 换装小游戏
儿童小游戏 牛牛小游戏
麻将小游戏 冒险小游戏
美媚小游戏 益智小游戏
体育小游戏  
Society Recreation & Sports
Travel & Leisure Communications
Vehicles Computers
Fashion Arts & Entertainment
Reference & Education Disease & Illness
Writing & Speaking Politics
Product Reviews Food & Beverage
Finance Internet Business
Self Improvement Home & Family
Health & Fitness Business
最新更新内容
警惕“公务员报考热”背
公务员考试不是丈母娘考
一名新公务员的自白:我
公务员考脑筋急转弯与挂
北努斗:2006行政能力测
大讨论:06行测BT题目大
过来人回忆:当年,我也
一家之言:公务员热折射
公务员考试申论要是有正
数十万大学生走进公务员
      粤ICP备05005424         Copyright ©2000 - 2004 Yesize.COM