国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > VBScript > 正文

用vbs實(shí)現(xiàn)zip功能的腳本

2020-06-26 18:11:13
字體:
供稿:網(wǎng)友
vbs實(shí)現(xiàn)壓縮功能的代碼
 
壓縮:  
Function fZip(sSourceFolder,sTargetZIPFile)  
'This function will add all of the files in a source folder to a ZIP file  
'using Windows' native folder ZIP capability.  
Dim oShellApp, oFSO, iErr, sErrSource, sErrDescription  
Set oShellApp = CreateObject("Shell.Application")  
Set oFSO = CreateObject("Scripting.FileSystemObject")  
'The source folder needs to have a / on the End  
If Right(sSourceFolder,1) <> "/" Then sSourceFolder = sSourceFolder & "/"  
On Error Resume Next   
'If a target ZIP exists already, delete it  
If oFSO.FileExists(sTargetZIPFile) Then oFSO.DeleteFile sTargetZIPFile,True   
iErr = Err.Number  
sErrSource = Err.Source  
sErrDescription = Err.Description  
On Error GoTo 0  
If iErr <> 0 Then     
fZip = Array(iErr,sErrSource,sErrDescription)  
Exit Function  
End If  
On Error Resume Next  
'Write the fileheader for a blank zipfile.  
oFSO.OpenTextFile(sTargetZIPFile, 2, True).Write "PK" & Chr(5) & Chr(6) & String(18, Chr(0))  
iErr = Err.Number  
sErrSource = Err.Source  
sErrDescription = Err.Description  
On Error GoTo 0  
If iErr <> 0 Then     
fZip = Array(iErr,sErrSource,sErrDescription)  
Exit Function  
End If  
On Error Resume Next   
'Start copying files into the zip from the source folder.  
oShellApp.NameSpace(sTargetZIPFile).CopyHere oShellApp.NameSpace(sSourceFolder).Items  
iErr = Err.Number  
sErrSource = Err.Source  
sErrDescription = Err.Description  
On Error GoTo 0  
If iErr <> 0 Then     
fZip = Array(iErr,sErrSource,sErrDescription)  
Exit Function  
End If  
'Because the copying occurs in a separate process, the script will just continue. Run a DO...LOOP to prevent the function  
'from exiting until the file is finished zipping.  
Do Until oShellApp.NameSpace(sTargetZIPFile).Items.Count = oShellApp.NameSpace(sSourceFolder).Items.Count  
   WScript.Sleep 1500'如果不成功,增加一下秒數(shù)  
Loop  
fZip = Array(0,"","")  
End Function   

Call fZip ("C:/vbs","c:/vbs.zip")  

 


解壓縮:  
Function fUnzip(sZipFile,sTargetFolder)  
'Create the Shell.Application object  
Dim oShellApp:Set oShellApp = CreateObject("Shell.Application")  
'Create the File System object  
Dim oFSO:Set oFSO = CreateObject("Scripting.FileSystemObject")  
'Create the target folder if it isn't already there  
If Not oFSO.FolderExists(sTargetFolder) Then oFSO.CreateFolder sTargetFolder  
'Extract the files from the zip into the folder  
oShellApp.NameSpace(sTargetFolder).CopyHere oShellApp.NameSpace(sZipFile).Items  
'This is a seperate process, so the script would continue even if the unzipping is not done  
'To prevent this, we run a DO...LOOP once a second checking to see if the number of files  
'in the target folder equals the number of files in the zipfile. If so, we continue.  
Do  
WScript.Sleep 1000‘有時(shí)需要更改  
Loop While oFSO.GetFolder(sTargetFolder).Files.Count < oShellApp.NameSpace(sZipFile).Items.Count  
End Function 
 

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 昌都县| 武安市| 吐鲁番市| 秭归县| 建水县| 南部县| 淮滨县| 沭阳县| 轮台县| 同仁县| 武冈市| 宁武县| 桑植县| 北海市| 西宁市| 和林格尔县| 沁源县| 嘉禾县| 望奎县| 阳东县| 彭泽县| 蓬莱市| 含山县| 柳林县| 巴里| 乌兰浩特市| 泾阳县| 巴中市| 临汾市| 商河县| 陕西省| 新沂市| 那曲县| 海兴县| 民权县| 南靖县| 德安县| 陕西省| 灵山县| 盖州市| 洞口县|