Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for extract.vbs

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

  1. Option Explicit
  2.  
  3. ' UnZip "C:\test.zip" into the folder "C:\test1"
  4. Extract "C:\test.zip", "C:\test1"
  5.  
  6. ' Extract "C:\test.cab" into the folder "C:\test2"
  7. Extract "C:\test.cab", "C:\test2"
  8.  
  9. ' Copy the contents of folder "C:\test2" to the folder "C:\test3"
  10. Extract "C:\test2", "C:\test3"
  11.  
  12.  
  13. Sub Extract( ByVal myZipFile, ByVal myTargetDir )
  14. ' Function to extract all files from a compressed "folder"
  15. ' (ZIP, CAB, etc.) using the Shell Folders' CopyHere method
  16. ' (http://msdn2.microsoft.com/en-us/library/ms723207.aspx).
  17. ' All files and folders will be extracted from the ZIP file.
  18. ' A progress bar will be displayed, and the user will be
  19. ' prompted to confirm file overwrites if necessary.
  20. '
  21. ' Note:
  22. ' This function can also be used to copy "normal" folders,
  23. ' if a progress bar and confirmation dialog(s) are required:
  24. ' just use a folder path for the "myZipFile" argument.
  25. '
  26. ' Arguments:
  27. ' myZipFile    [string]  the (path and) file name of the ZIP file
  28. ' myTargetDir  [string]  the path of the (existing) destination folder
  29. '
  30. ' Based on an article by Gerald Gibson Jr.:
  31. ' http://www.codeproject.com/csharp/decompresswinshellapics.asp
  32. '
  33. ' Written by Rob van der Woude
  34. ' http://www.robvanderwoude.com
  35.  
  36. 	Dim intOptions, objShell, objSource, objTarget
  37.  
  38. 	' Create the required Shell objects
  39. 	Set objShell = CreateObject( "Shell.Application" )
  40.  
  41. 	' Create a reference to the files and folders in the ZIP file
  42. 	Set objSource = objShell.NameSpace( myZipFile ).Items( )
  43.  
  44. 	' Create a reference to the target folder
  45. 	Set objTarget = objShell.NameSpace( myTargetDir )
  46.  
  47. 	' These are the available CopyHere options, according to MSDN
  48. 	' (http://msdn2.microsoft.com/en-us/library/ms723207.aspx).
  49. 	' On my test systems, however, the options were completely ignored.
  50. 	'      4: Do not display a progress dialog box.
  51. 	'      8: Give the file a new name in a move, copy, or rename
  52. 	'         operation if a file with the target name already exists.
  53. 	'     16: Click "Yes to All" in any dialog box that is displayed.
  54. 	'     64: Preserve undo information, if possible.
  55. 	'    128: Perform the operation on files only if a wildcard file
  56. 	'         name (*.*) is specified.
  57. 	'    256: Display a progress dialog box but do not show the file
  58. 	'         names.
  59. 	'    512: Do not confirm the creation of a new directory if the
  60. 	'         operation requires one to be created.
  61. 	'   1024: Do not display a user interface if an error occurs.
  62. 	'   4096: Only operate in the local directory.
  63. 	'         Don't operate recursively into subdirectories.
  64. 	'   9182: Do not copy connected files as a group.
  65. 	'         Only copy the specified files.
  66. 	intOptions = 256
  67.  
  68. 	' UnZIP the files
  69. 	objTarget.CopyHere objSource, intOptions
  70.  
  71. 	' Release the objects
  72. 	Set objSource = Nothing
  73. 	Set objTarget = Nothing
  74. 	Set objShell  = Nothing
  75. End Sub
  76.  

page last modified: 2024-02-26; loaded in 0.0140 seconds