Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for xzipdemo.vbs

(view source code of xzipdemo.vbs as plain text)

  1. Option Explicit
  2.  
  3. Zip "C:\boot.ini", "C:\testzip.zip"
  4.  
  5. UnZip "C:\testzip.zip", "D:\", "*.ini"
  6.  
  7.  
  8. Function Zip( myFileSpec, myZip )
  9. ' This function uses X-standards.com's X-zip component to add
  10. ' files to a ZIP file.
  11. ' If the ZIP file doesn't exist, it will be created on-the-fly.
  12. ' Compression level is set to maximum, only relative paths are
  13. ' stored.
  14. '
  15. ' Arguments:
  16. ' myFileSpec    [string] the file(s) to be added, wildcards allowed
  17. '                        (*.* will include subdirectories, thus
  18. '                        making the function recursive)
  19. ' myZip         [string] the fully qualified path to the ZIP file
  20. '
  21. ' Written by Rob van der Woude
  22. ' http://www.robvanderwoude.com
  23. '
  24. ' The X-zip component is available at:
  25. ' http://www.xstandard.com/page.asp?p=C8AACBA3-702F-4BF0-894A-B6679AA949E6
  26. ' For more information on available functionality read:
  27. ' http://www.xstandard.com/printer-friendly.asp?id=C9891D8A-5390-44ED-BC60-2267ED6763A7
  28. 	Dim objZIP
  29. 	On Error Resume Next
  30. 	Err.Clear
  31. 	Set objZIP = CreateObject( "XStandard.Zip" )
  32. 	objZIP.Pack myFileSpec, myZip, , , 9
  33. 	Zip = Err.Number
  34. 	Err.Clear
  35. 	Set objZIP = Nothing
  36. 	On Error Goto 0
  37. End Function
  38.  
  39.  
  40. Function UnZip( myZip, myTargetDir, myFileSpec )
  41. ' This function uses X-standards.com's X-zip component to extract files from a ZIP file.
  42. '
  43. ' Arguments:
  44. ' myZip         [string] the fully qualified path to the ZIP file
  45. ' myTargetDir   [string] the directory where the extracted files will be located
  46. ' myFileSpec    [string] the file(s) to be extracted, wildcards allowed
  47. '
  48. ' Written by Rob van der Woude
  49. ' http://www.robvanderwoude.com
  50. '
  51. ' The X-zip component is available at:
  52. ' http://www.xstandard.com/page.asp?p=C8AACBA3-702F-4BF0-894A-B6679AA949E6
  53. ' For more information on available functionality read:
  54. ' http://www.xstandard.com/printer-friendly.asp?id=C9891D8A-5390-44ED-BC60-2267ED6763A7
  55. 	Dim objZIP
  56. 	On Error Resume Next
  57. 	Err.Clear
  58. 	Set objZIP = CreateObject( "XStandard.Zip" )
  59. 	objZIP.UnPack myZip, myTargetDir, myFileSpec
  60. 	UnZip = Err.Number
  61. 	Err.Clear
  62. 	Set objZIP = Nothing
  63. 	On Error Goto 0
  64. End Function
  65.  

page last uploaded: 2017-07-06, 12:37