标题: [VBS]如果调用Winrar并执行压缩操作?
[打印本页]
作者: kich
时间: 2007-4-5 06:30
标题: [VBS]如果调用Winrar并执行压缩操作?
用的是VBS脚本,想针对某个文件夹(特定的文件夹,事先定义好了)进行压缩处理!假设这个文件夹有20个DOC文档吧!
怎么调用WinRar呢,压缩后的文件名就以该文件夹命名!
Ps:在对这个文件夹压缩的时候,有两个方式,一个是压缩里面的所有文件,不包括文件夹本身,还有个就是直接压缩文件夹本身,哪个简单,就用哪个吧!!
谢谢!!
作者: baomaboy
时间: 2007-4-5 06:36
自己去查winrar的命令参数 然后用VBS中的run
[
Last edited by baomaboy on 2007-4-6 at 03:06 AM ]
作者: kich
时间: 2007-4-5 09:40
查它就可以解决吗??查查看,谢谢
作者: kich
时间: 2007-4-6 01:37
看不明白,能不能提示一下,比如说举个例子!!
作者: mygoldnet
时间: 2007-4-6 01:41
RAR压缩的同步文件夹
'电脑爱好者专用版 编写:李兴旺 E-MAIL:wors_hip*163.com
MsgBox_Title_Text = "压缩的同步文件夹"
CompressionFolder = InputBox("请输入即将压缩的文件夹路径:", MsgBox_Title_Text, "C:\PHP")
If CompressionFolder = "" Then WScript.Quit
Function Interrogation(Contents)
Dim intButton
intButton = MsgBox(Contents, vbQuestion + vbYesNo, MsgBox_Title_Text )
Interrogation = intButton = vbYes
End Function
Function Compression(CompressionFolder)
FileName = "压缩的同步文件夹.vbs"
Set fso = CreateObject("Scripting.FileSystemObject")
Destination = UCase(fso.GetFile(FileName).Drive) & "\"
DIM cmd
set fso= wscript.CreateObject("wscript.shell")
cmd = "WINRAR A -IBCK -R " & Destination & "压缩的同步文件夹.RAR " & CompressionFolder
fso.run cmd
MsgBox "成功把 " & CompressionFolder & " 文件夹压缩到 " & Destination, vbInformation, MsgBox_Title_Text
End Function
If Interrogation("定时压缩文件夹,同步数据到闪盘,请点击“是”!" & vbCrLf & "马上压缩文件夹,同步数据到闪盘,请点击“否”!") Then
Savetime = InputBox("请输入24 小时格式 (hh:mm) 的时间:", MsgBox_Title_Text, "11:30")
If Savetime = "" Then WScript.Quit
MsgBox "已经运行了定时压缩文件夹,请不要重复运行!", vbExclamation, MsgBox_Title_Text
Dim Check
Check = True
Do
HHMM = FormatDateTime(Time, 4)
If HHMM = Savetime Then
Compression(CompressionFolder)
Exit Do
End If
Loop Until Check = False
Else
Compression(CompressionFolder)
End If
作者: baomaboy
时间: 2007-4-6 03:18
Quote: |
Originally posted by mygoldnet at 2007-4-6 01:41:
RAR压缩的同步文件夹
[code]
'电脑爱好者专用版 编写:李兴旺 E-MAIL:wors_hip*163.com
MsgBox_Title_Text = "压缩的同步文件夹"
CompressionFolder = InputBox ... |
|
代码可当参考范例。
不过眇第一眼时发现了"fso.run cmd"吃了一惊,FSO(FileSystemObject)什么时候多出个.run的方法啊,又仔细看了看
Set fso = CreateObject("Scripting.FileSystemObject")
然后
set fso= wscript.CreateObject("wscript.shell")
虽然可以但很使得代码可读性变差了(太容易产生歧意了)不如用个wshshell
作者: manxisuosy
时间: 2007-4-6 10:18
初学者,学习中。。。
作者: kich
时间: 2007-4-7 05:03
首先感谢mygoldnet提供代码,回去好好研究下!
baomaboy说的有道理,哪怕写简单点,写成 "Ws" 也OK啊
谢谢各位
作者: wjq0886
时间: 2007-5-24 22:19
这个代码好难。。。
作者: xswdong
时间: 2007-5-25 12:16
我是用最笨的方法.
regedit /s D:\m\Settings.reg
"C:\Program Files\WinRAR\WinRAR.exe" "-cp新建配置 6"
regedit /s "D:\m\删除Settings.reg"
其中Settings.reg就是事先导出的WinRAR注册表文件
删除Settings.reg就是删除cp新建配置 6的注册表文件,以前写的用习惯了.
作者: zhoushijay
时间: 2007-5-25 17:17
汗 fso.run是什么?
还是在CMD里操作,还不如直接用BAT
[
Last edited by zhoushijay on 2007-5-25 at 05:21 PM ]