用asp實(shí)現(xiàn)的代碼批量修改程序,fso相關(guān) 是因工作需要做的一個批量修改代碼的小東西,拿出來與大家分享 目前可以處理的文件類型:.asp .inc .htm .html 具體類型可自行修改添加
程序?qū)崿F(xiàn)的功能:將源目錄下的文件批量修改后存到目的目錄下 用它稍做修改可以實(shí)現(xiàn)很多東西噢!別的不說了,代碼里面都寫的很清楚了
- <%
- '// +---------------------------------------------------------------------------+
- '// | 程序名稱: 他山之石代碼批量修改器 v1.01 |
- '// | 他山之石版權(quán)所有,侵權(quán)必究!轉(zhuǎn)載請注明版權(quán):) |
- '// | ------------------------------------------------------------------------- |
- '// | 系統(tǒng):win2000; 編輯器:EditPlus; 縮進(jìn)工具:Tab; 縮進(jìn)長度:8; 字體:宋體(10pt); |
- '// | ------------------------------------------------------------------------- |
- '// | 創(chuàng)建者: WYC; 創(chuàng)建時間: 2004-03-08; |
- '// | 編寫者: WYC; 編寫時間: 2004-03-08; |
- '// +---------------------------------------------------------------------------+
- Server.ScriptTimeOut = 500 '腳本超時時間
- '// +---------------------------------------------------------------------------+
- '// | 批量修改函數(shù) |
- '// | ------------------------------------------------------------------------- |
- '// | 屬性:path_from 源文件目錄 path_to 目標(biāo)文件工作目錄 |
- '// | ------------------------------------------------------------------------- |
- '// | 返回值:無 |
- '// | ------------------------------------------------------------------------- |
- '// | 程序流程:...... |
- '// | ------------------------------------------------------------------------- |
- '// | 編寫者:WYC; 編寫時間: 2004-03-08; |
- '// +---------------------------------------------------------------------------+
- Sub midfile(path_from, path_to)
- list_from = path_from '儲存當(dāng)前源工作目錄
- list_to = path_to '儲存當(dāng)前目標(biāo)工作目錄
- 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) '創(chuàng)建目錄
- midfile path_from & "\" & f2.name, path_to & "\" & f2.name '遞歸調(diào)用
- 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") '定義一個服務(wù)器組件(讀取源文件)
- set out = objfile.opentextfile(file_from, 1, false, false)
- content = out.readall '讀取數(shù)據(jù)
- out.close
- '// +---------------------------------------------------+
- '// | 文件內(nèi)容處理模塊(主要,其他都是文件操作) |
- Set regEx = New RegExp
- regEx.Pattern = "(\>\s*\n)"
- regEx.Global = true '設(shè)置全部匹配模式
- content = regEx.Replace(content, ">") '替換掉回車符
- content = Replace(content, " ", "") '作tab替換
- '// +---------------------------------------------------+
- set objfile = server.createobject("scripting.filesystemobject") '定義一個服務(wù)器組件(寫入目標(biāo)文件)
- set outt = objfile.createtextfile(file_to,TRUE,FALSE)
- outt.write(content) '寫入數(shù)據(jù)
- outt.close
- else '否則直接復(fù)制文件
- 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") '調(diào)用示例 源目錄temp/aaa 處理后存到temp/bbb
- '源目錄 目的目錄(必須是已經(jīng)存在的目錄)
- %>