DDR爱好者之家 Design By 杰米
为了解决这类问题,我使用Visual Basic Scripting设计了一个脚本,可以自动达到这个目标。在本脚本中,自动压缩所有文件。为了避免将脚本自己也压缩进去,使用了一些判断。
复制代码 代码如下:
call main()
Sub main()
Dim fs '文件系统。
Dim f 'folder
Dim fc 'files
Dim s 'string
Dim ws 'SHELL。
Dim subfs
Dim fi
'创建SHELL。
Set ws = CreateObject("WScript.Shell")
'创建文件对象。
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(ws.currentdirectory)
Handle_files(ws.currentdirectory)
Set subfs = f.SubFolders
'遍历每个子目录。
For Each fi In subfs
Call ListSub(fi.Path)
Next
End Sub
Sub ListSub(filename)
On Error Resume Next
Dim subfs '子目录。
'首先处理当前目录。
Handle_Files(filename)
'创建文件对象。
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(filename)
Set subfs = f.SubFolders
For Each fi In subfs
Call ListSub(fi.Path)
Next
End Sub
'处理每个目录下的文件。
Sub Handle_Files(foldername)
'创建文件对象。
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(foldername)
Set fc = f.Files
'创建SHELL。
Set ws = CreateObject("WScript.Shell")
'遍历文件对象。
For Each fl In fc
if ((instr(fl.Name,"vbs") = 0) and (instr(fl.Name,"rar") = 0)) then
'进行压缩。
s = "winrar M -ep " & fl.Path & ".rar " & fl.Path
ws.Run s, 0, True
End If
Next
End Sub
sub output(string)
wscript.echo string
end sub
一种更加巧妙的方法
对上个脚本稍加改动,使用正则表达式(Regular Expression ),可以方便我们的判断过程。修改后的脚本程序如下所示。注意我们这里排除的是不压缩的文件类型。
复制代码 代码如下:
call main()
Sub main()
Dim fs '文件系统。
Dim f 'folder
Dim fc 'files
Dim s 'string
Dim ws 'SHELL。
Dim subfs
Dim fi
'创建SHELL。
Set ws = CreateObject("WScript.Shell")
'创建文件对象。
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(ws.currentdirectory)
Handle_files(ws.currentdirectory)
Set subfs = f.SubFolders
'遍历每个子目录。
For Each fi In subfs
Call ListSub(fi.Path)
Next
End Sub
Sub ListSub(filename)
On Error Resume Next
Dim subfs '子目录。
'首先处理当前目录。
Handle_Files(filename)
'创建文件对象。
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(filename)
Set subfs = f.SubFolders
For Each fi In subfs
Call ListSub(fi.Path)
Next
End Sub
'处理每个目录下的文件。
Sub Handle_Files(foldername)
'创建文件对象。
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(foldername)
Set fc = f.Files
'创建SHELL。
Set ws = CreateObject("WScript.Shell")
'遍历文件对象。
For Each fl In fc
if ( RegExpTest(".vbs|.rar|.zip",fl.name) = false) then
'进行压缩。
s = "winrar M -ep " & fl.Path & ".rar " & fl.Path
output s
ws.Run s, 0, True
End If
Next
End Sub
sub output(string)
wscript.echo string
end sub
'使用正则表达式进行判断。
Function RegExpTest(patrn, strng)
Dim regEx, retVal ' Create variable.
Set regEx = New RegExp ' Create regular expression.
regEx.Pattern = patrn ' Set pattern.
regEx.IgnoreCase = False ' Set case sensitivity.
retVal = regEx.Test(strng) ' Execute the search test.
If retVal Then
RegExpTest = true
Else
RegExpTest = false
End If
End Function
复制代码 代码如下:
call main()
Sub main()
Dim fs '文件系统。
Dim f 'folder
Dim fc 'files
Dim s 'string
Dim ws 'SHELL。
Dim subfs
Dim fi
'创建SHELL。
Set ws = CreateObject("WScript.Shell")
'创建文件对象。
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(ws.currentdirectory)
Handle_files(ws.currentdirectory)
Set subfs = f.SubFolders
'遍历每个子目录。
For Each fi In subfs
Call ListSub(fi.Path)
Next
End Sub
Sub ListSub(filename)
On Error Resume Next
Dim subfs '子目录。
'首先处理当前目录。
Handle_Files(filename)
'创建文件对象。
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(filename)
Set subfs = f.SubFolders
For Each fi In subfs
Call ListSub(fi.Path)
Next
End Sub
'处理每个目录下的文件。
Sub Handle_Files(foldername)
'创建文件对象。
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(foldername)
Set fc = f.Files
'创建SHELL。
Set ws = CreateObject("WScript.Shell")
'遍历文件对象。
For Each fl In fc
if ((instr(fl.Name,"vbs") = 0) and (instr(fl.Name,"rar") = 0)) then
'进行压缩。
s = "winrar M -ep " & fl.Path & ".rar " & fl.Path
ws.Run s, 0, True
End If
Next
End Sub
sub output(string)
wscript.echo string
end sub
一种更加巧妙的方法
对上个脚本稍加改动,使用正则表达式(Regular Expression ),可以方便我们的判断过程。修改后的脚本程序如下所示。注意我们这里排除的是不压缩的文件类型。
复制代码 代码如下:
call main()
Sub main()
Dim fs '文件系统。
Dim f 'folder
Dim fc 'files
Dim s 'string
Dim ws 'SHELL。
Dim subfs
Dim fi
'创建SHELL。
Set ws = CreateObject("WScript.Shell")
'创建文件对象。
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(ws.currentdirectory)
Handle_files(ws.currentdirectory)
Set subfs = f.SubFolders
'遍历每个子目录。
For Each fi In subfs
Call ListSub(fi.Path)
Next
End Sub
Sub ListSub(filename)
On Error Resume Next
Dim subfs '子目录。
'首先处理当前目录。
Handle_Files(filename)
'创建文件对象。
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(filename)
Set subfs = f.SubFolders
For Each fi In subfs
Call ListSub(fi.Path)
Next
End Sub
'处理每个目录下的文件。
Sub Handle_Files(foldername)
'创建文件对象。
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(foldername)
Set fc = f.Files
'创建SHELL。
Set ws = CreateObject("WScript.Shell")
'遍历文件对象。
For Each fl In fc
if ( RegExpTest(".vbs|.rar|.zip",fl.name) = false) then
'进行压缩。
s = "winrar M -ep " & fl.Path & ".rar " & fl.Path
output s
ws.Run s, 0, True
End If
Next
End Sub
sub output(string)
wscript.echo string
end sub
'使用正则表达式进行判断。
Function RegExpTest(patrn, strng)
Dim regEx, retVal ' Create variable.
Set regEx = New RegExp ' Create regular expression.
regEx.Pattern = patrn ' Set pattern.
regEx.IgnoreCase = False ' Set case sensitivity.
retVal = regEx.Test(strng) ' Execute the search test.
If retVal Then
RegExpTest = true
Else
RegExpTest = false
End If
End Function
DDR爱好者之家 Design By 杰米
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
DDR爱好者之家 Design By 杰米
暂无评论...
P70系列延期,华为新旗舰将在下月发布
3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。
而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?
根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。
更新日志
2024年05月16日
2024年05月16日
- 林一峰2018-TRAVELOGUE4ESCAPE[香港首版][WAV+CUE]
- MollyLewis《OnTheLips》(2024)[Hi-Res96kHz_24bitFLAC]
- Joyce Jonathan《法式松弛感 漫步香榭丽舍》[FLAC/分轨][230.77MB]
- 群星《影视剧 春色寄情人 原声带》[320K/MP3][394.18MB]
- 吴牧野《强者独白II 李斯特巅峰作品选》[320K/MP3][216.01MB]
- 女神异闻录5御船千早coop攻略 p5r御船千早对话选项攻略
- dnf神话装备怎么获得
- dnf称号附魔
- 乌兰托娅.2024-《八月草儿飞HQ》头版限量编号[低速原抓WAV+CUE]
- 雷婷.2024-《寂寞烟火HQ》头版限量编号[低速原抓WAV+CUE]
- [ABC唱片]-《西电之声—人声》[HD-201][德国版HD]WAV+CUE
- dnf紧急任务怎么触发
- dnf紫牌能翻出什么
- 星穹铁道2.2上升的一切必将汇合怎么过 上升的一切必将汇合流程攻略
- [ABC唱片]-《西电之声—人声》[HD-201][德国版HD]WAV+CUE