2016-01-22 27 views
-4
**I would need a simple script that will zip a file using vb script 

''basically my requirement is like below 

「」我在路徑下的文件象下面這樣: 「」 d:\開發\ Efforts.csv enter code here 「」需要檢查,如果Efforts.csv是存在的,如果存在的話做了以下 '將文件Efforts.csv壓縮到Efforts.zip並刪除原Efforts.csv **如何使用vb腳本壓縮文件?

+2

不,這不是這個工作原理。您需要向我們展示*迄今爲止您嘗試過的*。如果您在該代碼的*特定部分中遇到問題,我們可能會幫助您解決該問題。我們不會爲您編寫代碼,並且要求提供資源或書籍的問題不在話題中。 –

回答

0

我在谷歌上得到了一些代碼 嗨,謝謝..我有一些代碼可以在谷歌上使用。其工作

昏暗FSO FSO設置=的CreateObject( 「Scripting.FileSystemObject的」)

CONST FOF_CREATEPROGRESSDLG = & H0 &

CONST MyZip = 「d:\ Sravan \拉鍊\ zipthefile.zip」

常量文件1 = 「d:\ Sravan \郵編\ zipthefile.txt」

'常量MyDest = 「C:\從零開始」' 可以,如果你需要完成一次移動拉鍊使用此變種I S uppose。不知道爲什麼,他在離開這個其實這裏:)

「--------------創建空的zip文件---------

」創建一個zip文件的基礎。 的CreateObject( 「Scripting.FileSystemObject的」)_ .CreateTextFile(MyZip,真)_ .WRITE 「PK」 & CHR(5)& CHR(6)&字符串(18,vbNullChar)

「--- ----------- zip ---------------------------

'準備添加文件到拉鍊 用的CreateObject( 「Shell.Application」)

「添加文件 .NameSpace(MyZip).MoveHere文件1,FOF_CREATEPROGRESSDLG

以 結尾wScript.Sleep 1000

wscript.echo「完成!」

0
'The location of the zip file. 
ZipFile="C:\TestStare.zip" 
'The folder the contents should be extracted to. 
ExtractTo="C:\ExtractTestStare\" 

'If the extraction location does not exist create it. 
Set fso = CreateObject("Scripting.FileSystemObject") 
If NOT fso.FolderExists(ExtractTo) Then 
    fso.CreateFolder(ExtractTo) 
End If 

'Extract the contants of the zip file. 
set objShell = CreateObject("Shell.Application") 
set FilesInZip=objShell.NameSpace(ZipFile).items 
objShell.NameSpace(ExtractTo).CopyHere(FilesInZip) 
Set fso = Nothing 
Set objShell = Nothing