一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

腳本之家,腳本語言編程技術及教程分享平臺!
分類導航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服務器之家 - 腳本之家 - VBS - 用vbs實現zip功能的腳本

用vbs實現zip功能的腳本

2020-07-17 11:09VBS代碼網 VBS

本文主要講解用vbs腳本實現zip壓縮及解壓縮功能的實現方法,有需要的朋友可以參考下

壓縮: 

  1. Function fZip(sSourceFolder,sTargetZIPFile)  
  2. 'This function will add all of the files in a source folder to a ZIP file  
  3. 'using Windows' native folder ZIP capability.  
  4. Dim oShellApp, oFSO, iErr, sErrSource, sErrDescription  
  5. Set oShellApp = CreateObject("Shell.Application")  
  6. Set oFSO = CreateObject("Scripting.FileSystemObject")  
  7. 'The source folder needs to have a \ on the End  
  8. If Right(sSourceFolder,1) <> "\" Then sSourceFolder = sSourceFolder & "\"  
  9. On Error Resume Next   
  10. 'If a target ZIP exists already, delete it  
  11. If oFSO.FileExists(sTargetZIPFile) Then oFSO.DeleteFile sTargetZIPFile,True   
  12. iErr = Err.Number  
  13. sErrSource = Err.Source  
  14. sErrDescription = Err.Description  
  15. On Error GoTo 0  
  16. If iErr <> 0 Then     
  17. fZip = Array(iErr,sErrSource,sErrDescription)  
  18. Exit Function  
  19. End If  
  20. On Error Resume Next  
  21. 'Write the fileheader for a blank zipfile.  
  22. oFSO.OpenTextFile(sTargetZIPFile, 2, True).Write "PK" & Chr(5) & Chr(6) & String(18, Chr(0))  
  23. iErr = Err.Number  
  24. sErrSource = Err.Source  
  25. sErrDescription = Err.Description  
  26. On Error GoTo 0  
  27. If iErr <> 0 Then     
  28. fZip = Array(iErr,sErrSource,sErrDescription)  
  29. Exit Function  
  30. End If  
  31. On Error Resume Next   
  32. 'Start copying files into the zip from the source folder.  
  33. oShellApp.NameSpace(sTargetZIPFile).CopyHere oShellApp.NameSpace(sSourceFolder).Items  
  34. iErr = Err.Number  
  35. sErrSource = Err.Source  
  36. sErrDescription = Err.Description  
  37. On Error GoTo 0  
  38. If iErr <> 0 Then     
  39. fZip = Array(iErr,sErrSource,sErrDescription)  
  40. Exit Function  
  41. End If  
  42. 'Because the copying occurs in a separate process, the script will just continue. Run a DO...LOOP to prevent the function  
  43. 'from exiting until the file is finished zipping.  
  44. Do Until oShellApp.NameSpace(sTargetZIPFile).Items.Count = oShellApp.NameSpace(sSourceFolder).Items.Count  
  45.    WScript.Sleep 1500'如果不成功,增加一下秒數  
  46. Loop  
  47. fZip = Array(0,"","")  
  48. End Function   
  49.  
  50. Call fZip ("C:\vbs","c:\vbs.zip")   

解壓縮: 
 

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

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 强波多野结衣女教师 | 18美女光胸光屁屁洗澡 | 52zfl宅福利yxpjw | 国产福利自产拍在线观看 | 猛男深夜狂cao小男生 | 国产精品29页 | 睡男神的这件小事小说在线阅读 | 99re在线精品视频免费 | 国产99久久九九精品免费 | 给我免费观看的视频在线播放 | 成年男女免费大片在线观看 | 国产在线精品成人一区二区三区 | 娇妻与老头绿文小说系列 | 国内自拍网红在综合图区 | 亚洲 色 欧美 爱 视频 日韩 | 四虎精品成人免费视频 | 500av导航大全精品 | 午夜亚洲福利 | 网www天堂资源在线 王淑兰与铁柱全文免费阅读 | 亚洲免费在线看 | 亚洲国产午夜 | 999任你躁在线精品免费不卡 | 午夜久久免影院欧洲 | 亚洲国产精品无码中文字幕 | 国产99久久久国产精品成人 | 99自拍视频在线观看 | 欧美视频在线一区 | 青草香蕉精品视频在线观看 | 免费在线观看视频 | 黄色大片网站 | 91最新国产 | 亚洲AV永久无码精品老司机蜜桃 | sese在线观看 | 小泽玛丽av无码观看 | 99精品国产综合久久久久 | 5x视频在线观看 | 97影院伦理| 国产精彩对白综合视频 | 欧美区在线 | 青草香蕉精品视频在线观看 | 国产男人搡女人免费视频 |