本帖最后由 apang 于 2013-2-25 15:27 编辑
- fPath = "d:\log"
- '待压缩的log文件所在目录
- Rar = "C:\Program Files\WinRAR\winrar.exe"
- 'winrar安装路径
- Set Ws = CreateObject("Wscript.Shell")
- Set FSO = CreateObject("Scripting.FileSystemObject")
- For Each File in FSO.GetFolder(fPath).Files '遍历文件
- Set Re = New RegExp '建立正则表达式
- Re.IgnoreCase = True '忽略大小写
- Re.Pattern = "^test\.(\d{8}_\d{2})\d{4}_\d{3}\.log$"
- '正则表达式模式
- For Each a in Re.Execute(File.Name) '遍历匹配集合
- Zip = fPath & "\" & a.SubMatches(0) & ".zip"
- '压缩后的文件路径及文件名
- Ws.Run """" & Rar & """ a -afzip -ep """ & Zip &_
- """ """ & File & """",0,True
- '调用winrar压缩
- Next
- Set Re = Nothing
- Next
复制代码 保存为test.vbs,试试 |