0
我想將一個文件添加到一個文件夾,並將其保存爲VBScript中的壓縮文件夾。爲什麼這個VBScript不會將文件添加到ZIP文件?
我已經寫了下面的代碼,但它只創建ZIP文件,並沒有將文件添加到它。這個代碼有什麼問題?
Option Explicit
dim wshShell
Const MoveMode = True
Const BackupDir = "D:\csv\Image\"
Const Outfilename = "MyZip.zip"
Const TimeoutMins = 10 ' Timeout for individual file compression operation
'Set wshShell = CreateObject("WScript.shell")
Dim FSO : set FSO = CreateObject("Scripting.FileSystemObject")
Dim Folder : Set Folder = FSO.GetFolder("D:\csv\Image")
Dim Files : Set Files = Folder.Files
Dim File
Dim Counter : Counter=0
Dim Timeout : Timeout = 0
FSO.CreateTextFile "D:\csv\" & OutFilename,true '.WriteLine "PK" & Chr(5) & Chr(6) & String(18, 0)
Dim Shell : Set Shell = CreateObject("Shell.Application")
Dim ZipFile: Set ZipFile = Shell.NameSpace("D:\csv\"& OutFilename)
If Not ZipFile Is Nothing Then
Shell.NameSpace("D:\csv\"&Outfilename).CopyHere "D:\csv\Image\calender.png"
End If
你能告訴我們你有什麼了嗎? – redhotspike
可能重複[可以Windows'內置ZIP壓縮腳本?](http://stackoverflow.com/questions/30211/can-windows-built-in-zip-compression-be-scripted) –
我認爲'CopyHere()'是異步的(如果這是你的完整的代碼清單),你的腳本過程在任何文件被複制之前結束。 – 2012-12-06 09:10:14