Zip & Extract VBScript With User Interface

General Macro Scheduler discussion

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Zip & Extract VBScript With User Interface

Post by Rain » Fri Mar 29, 2013 5:01 pm

This script is using the VBScript examples I posted here to extract, compress a single file or content of a folder.

Code: Select all

LET>APP_TITLE=Simple Zip & Extract


Dialog>Dialog1
object Dialog1: TForm
  Left = 479
  Top = 148
  HelpContext = 5000
  BorderIcons = [biSystemMenu, biMinimize]
  BorderStyle = bsSingle
  Caption = 'Simple Zip & Extract App'
  ClientHeight = 164
  ClientWidth = 271
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  Icon.Data = {
    0000010001001010000001002000680400001600000028000000100000002000
    0000010020000000000040040000000000000000000000000000000000000000
    0000000000000000000000000000000000000000000000000000352F28032723
    1E0A40393103433B3304312B250A4B4339044B433903362F290A4D443A030000
    0000000000000000000000000000000000000000000000000000201C173B4D43
    379E1E1A154D26211D56584E439F26221D561E1A154D4D43379E201C173B0000
    000000000000000000000000000000000000000000000000000051473C87C8B4
    A1FFA4907AFFB6A28DFFAF9B85FF9D8972FFA4917BFFC8B4A1FF51473C870000
    000051565706000000230000002C0000002C0000002C0000002C26221D4C564C
    41A048413A346359508BAF9B86FF796957A06A5F53269787758087796A24455A
    6304241F1A4DBAA996F0C4B29FFFC4B29FFFC4B29FFFC4B29FFFC4B29FFFC3B0
    9DFF746758AC6E6257A3AE9A84FF7B6B59B926211C45161310315F554B042B40
    480DBBAB97EFE1D6C6FFDFD5C5FFDFD5C5FFDFD5C5FFDFD5C5FFDFD4C5FFDFD5
    C6FFD2C3B0FFC0AE9AFFC1AF9BFFC1B09BFFC1AF9BFFB3A390F0443D350A071D
    2D43618399FF5D8198FF5D8198FF5D8198FF5D8198FF5D8198FF5B7D93EA7D6D
    5CAFD2C8B9FFDFD5C6FFDFD5C6FFDED4C6FFDED5C6FFC4B7A7FF463F3708103F
    628A53C7F2FF45B4E8FF46B5E8FF46B5E8FF46B5E8FF48B9EAFF42B0E5FF3F49
    4B0C6A64586F917C68FFA08B75FFB4A48EFF6B5D4E8292816E6C887B6C01103F
    628A4EB8EAFF5BCCF4FF5ACCF3FF5ACCF3FF5ACCF3FF49B4E7FF49B2E3FF404D
    500B424B4D07BCAF9FD4B4A390FF7A6857D3433D36080000000000000000103E
    628A64CDF4FF5DC1EDFF5DC1EDFF5DC1EDFF5DC1EDFF5CC2EEFF4EB4E5FF3D4C
    510B3F4B4E07B8A694FF9B8571FF9F9280D449423B0700000000000000000F3E
    628A62C6EFFF3FB1E5FF40B1E5FF40B1E5FF40B1E5FF45B0E4FF55B7E6FF3D4C
    510B3F4B4E08786759CDC6B6A1FFB3A48FFF49433C0700000000000000000F3E
    628A6BCAF2FF60C1EDFF60C1EDFF60C1EDFF60C1EDFF59B9E9FF5ABAE9FF2027
    291200000025A4988AD1B4A490FF7A6957D40000003000000023675D52042968
    927F4FB2E5FF4CB1E5FF4DB1E5FF4DB1E5FF4CB1E5FF4CB0E5FF3A9FDBFE2D26
    1F60A5927DF0B8A692FFB8A692FFBAA995FFBBA995FFAC9C89F0433D360A3550
    5C08BFA58BFFC5AC93FFC5AC93FFC5AC93FFC5AC93FFC5AC93FFC3AD94FFC3B2
    9DFFDDD1C1FFDDD3C4FFDDD3C4FFDDD3C4FFDDD3C4FFC6B8A8FF443E370873A2
    B501A09D9198D5C9B7FFDDD4C5FFDDD4C5FFDDD4C5FFDDD4C5FFDDD4C5FFDCD3
    C5FFC0B2A1EAA19889809F93827FA0907D7FA1917F7FA0907D6C8F8375010000
    000086A6B2019B9E986B9C9F997F9D9F997FA0A0977FA19E947FA39E927FA59E
    927FA39F952D000000000000000000000000000000000000000000000000FE00
    0000FE000000FE00000080000000000000000000000000000000000000000003
    0000000300000003000000000000000000000000000000000000803F0000}
  Menu = MainMenu
  OldCreateOrder = True
  Position = poScreenCenter
  ShowHint = True
  OnTaskBar = True
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 8
    Top = 72
    Width = 104
    Height = 13
    Caption = 'Zip Archive to Extract'
    Font.Charset = ANSI_CHARSET
    Font.Color = clWindowText
    Font.Height = -11
    Font.Name = 'Tahoma'
    Font.Style = []
    ParentFont = False
  end
  object Label2: TLabel
    Left = 8
    Top = 120
    Width = 81
    Height = 13
    Caption = 'Output Directory'
    Font.Charset = ANSI_CHARSET
    Font.Color = clWindowText
    Font.Height = -11
    Font.Name = 'Tahoma'
    Font.Style = []
    ParentFont = False
  end
  object Label3: TLabel
    Left = 8
    Top = 0
    Width = 135
    Height = 13
    Caption = 'Extract && Compress Options'
    Font.Charset = ANSI_CHARSET
    Font.Color = clWindowText
    Font.Height = -11
    Font.Name = 'Tahoma'
    Font.Style = []
    ParentFont = False
  end
  object Edit1: TEdit
    Left = 8
    Top = 88
    Width = 232
    Height = 24
    BevelKind = bkTile
    BorderStyle = bsDialog
    Color = clBtnFace
    Font.Charset = ANSI_CHARSET
    Font.Color = clWindowText
    Font.Height = -13
    Font.Name = 'Tahoma'
    Font.Style = []
    ParentFont = False
    ReadOnly = True
    TabOrder = 3
  end
  object Edit2: TEdit
    Left = 8
    Top = 136
    Width = 232
    Height = 24
    BevelKind = bkTile
    BorderStyle = bsDialog
    Color = clBtnFace
    Font.Charset = ANSI_CHARSET
    Font.Color = clWindowText
    Font.Height = -13
    Font.Name = 'Tahoma'
    Font.Style = []
    ParentFont = False
    ReadOnly = True
    TabOrder = 4
  end
  object MSButton1: tMSButton
    Left = 240
    Top = 88
    Width = 24
    Height = 24
    Cursor = crHandPoint
    Hint = 'browse...'
    Font.Charset = ANSI_CHARSET
    Font.Color = clWindowText
    Font.Height = -11
    Font.Name = 'Tahoma'
    Font.Style = []
    Glyph.Data = {
      36050000424D3605000000000000360400002800000010000000100000000100
      080000000000000100000000000000000000000100000000000000000000FFFF
      FF000080000000808000800000008000800080800000C0C0C000808080000000
      FF0000FF000000FFFF00FF000000FF00FF00FFFF000000008000090909001212
      12001F1F1F002C2C2C003939390045454500525252005F5F5F006C6C6C007878
      780085858500929292009F9F9F00ABABAB00B8B8B800C5C5C500D2D2D200DEDE
      DE00EBEBEB00F8F8F800F0FBFF00A4A0A000C0DCC000F0CAA60000003E000000
      5D0000007C0000009B000000BA000000D9000000F0002424FF004848FF006C6C
      FF009090FF00B4B4FF0000143E00001E5D0000287C0000329B00003CBA000046
      D9000055F000246DFF004885FF006C9DFF0090B5FF00B4CDFF00002A3E00003F
      5D0000547C0000699B00007EBA000093D90000AAF00024B6FF0048C2FF006CCE
      FF0090DAFF00B4E6FF00003E3E00005D5D00007C7C00009B9B0000BABA0000D9
      D90000F0F00024FFFF0048FFFF006CFFFF0090FFFF00B4FFFF00003E2A00005D
      3F00007C5400009B690000BA7E0000D9930000F0AA0024FFB60048FFC2006CFF
      CE0090FFDA00B4FFE600003E1400005D1E00007C2800009B320000BA3C0000D9
      460000F0550024FF6D0048FF85006CFF9D0090FFB500B4FFCD00003E0000005D
      0000007C0000009B000000BA000000D9000000F0000024FF240048FF48006CFF
      6C0090FF9000B4FFB400143E00001E5D0000287C0000329B00003CBA000046D9
      000055F000006DFF240085FF48004398D2003D94D0003A92CF004197D100DCFC
      FF00D8F7FF00DBFAFF00358ECD003991CE003B92CF00D5F7FF0060D1F90061D0
      F800B4EBFD00D9F6FF00DAF8FF00DBF9FF00DCFAFF00DCFBFF00E0FFFF003E95
      D000CAF6FF0069D5F9006CD5F9006BD5F90069D5FA006AD7FB0068D4FA005EC7
      F1005EC7F2005DC8F200B4E3F8003F8FC6003C92CF00C0F3FF0071DAFB0074DB
      FB0075DBFC0076DCFC0073DAFA00449CD400378CCB00368CCB00358CCC00348D
      CC003890CE003D92CF00B9F4FF0073DBFB006BCCF2006CCDF3006CCEF3006DCE
      F300479CD40056BAE900D7F6FF00D6F6FF00D5F6FF00DBFCFF003E94D000ABF0
      FF00449DD600378BCB005CBEEA006FD9FB006AD6FA0068D5F90067D4F90066D4
      F90082DEFC00AAE0F6003885BC004095D0008AD7F50044A1D800DDFDFF00DAFA
      FF00DEFAFF0074DCFC0076DBFA0075DAFA0074DAFA0072D9FA00A1E8FF007CBF
      E6004296D1006BBEE8006DBDE600BBF2FF0075DEFD0077DEFC0078DEFC007BDF
      FC007DDFFC007CDFFC0080E0FD00ADF0FF004D9DD3004FA6D9008EDAF500A2EE
      FF0082E5FE0084E5FE0085E6FE0084E6FE0096EBFF008CD8F5003985BC004499
      D2003F94D000ABFBFF009BF3FF0092F1FF0093F1FF00A6F8FF0065B8E3004598
      D1004094D0003E92CF003E92CE003F92CE003F93CF004194CE00000000000000
      0000000000000000000000000000000000000000000000000000F985FAFBFCFD
      FDFDFDFDFDFDFEFF0000F1F2F3F4F5F6F6F6F6F6F6F6F7F8000085E7E8E9EAEB
      EBECECECECEDEEEFF000DADBDCDDDEDFE0E1E2E2E2E3E4E5E600CDCECFD0D18B
      D2D3D4D5D6D6D7D8D900C0C1C2AFAFAFC3C4C5C6C7C8C9CACBCCB3B4B5B6B7B8
      B9BABB94BCBDBE8FBFC0A6A7A8A9AAAAABACADAEAFB0B1B286858E9A9B9C9D9B
      9E9FA0A1A2A3A486A5008E8F909192939494959696979899000086898A8A8B8C
      8D878787878E8685000085868787868800000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000}
    ParentFont = False
    TabOrder = 1
    DoBrowse = False
    Filter = 'Archive (*.zip)|*.zip|'
    BrowseStyle = fbOpen
  end
  object MSButton2: tMSButton
    Left = 240
    Top = 136
    Width = 24
    Height = 24
    Cursor = crHandPoint
    Hint = 'browse...'
    Font.Charset = ANSI_CHARSET
    Font.Color = clWindowText
    Font.Height = -11
    Font.Name = 'Tahoma'
    Font.Style = []
    Glyph.Data = {
      36050000424D3605000000000000360400002800000010000000100000000100
      080000000000000100000000000000000000000100000000000000000000FFFF
      FF000080000000808000800000008000800080800000C0C0C000808080000000
      FF0000FF000000FFFF00FF000000FF00FF00FFFF000000008000090909001212
      12001F1F1F002C2C2C003939390045454500525252005F5F5F006C6C6C007878
      780085858500929292009F9F9F00ABABAB00B8B8B800C5C5C500D2D2D200DEDE
      DE00EBEBEB00F8F8F800F0FBFF00A4A0A000C0DCC000F0CAA60000003E000000
      5D0000007C0000009B000000BA000000D9000000F0002424FF004848FF006C6C
      FF009090FF00B4B4FF0000143E00001E5D0000287C0000329B00003CBA000046
      D9000055F000246DFF004885FF006C9DFF0090B5FF00B4CDFF00002A3E00003F
      5D0000547C0000699B00007EBA000093D90000AAF00024B6FF0048C2FF006CCE
      FF0090DAFF00B4E6FF00003E3E00005D5D00007C7C00009B9B0000BABA0000D9
      D90000F0F00024FFFF0048FFFF006CFFFF0090FFFF00B4FFFF00003E2A00005D
      3F00007C5400009B690000BA7E0000D9930000F0AA0024FFB60048FFC2006CFF
      CE0090FFDA00B4FFE600003E1400005D1E00007C2800009B320000BA3C0000D9
      460000F0550024FF6D0048FF85006CFF9D0090FFB500B4FFCD00003E0000005D
      0000007C0000009B000000BA000000D9000000F0000024FF240048FF48006CFF
      6C0090FF9000B4FFB400143E00001E5D0000287C0000329B00003CBA000046D9
      000055F000006DFF240085FF48004398D2003D94D0003A92CF004197D100DCFC
      FF00D8F7FF00DBFAFF00358ECD003991CE003B92CF00D5F7FF0060D1F90061D0
      F800B4EBFD00D9F6FF00DAF8FF00DBF9FF00DCFAFF00DCFBFF00E0FFFF003E95
      D000CAF6FF0069D5F9006CD5F9006BD5F90069D5FA006AD7FB0068D4FA005EC7
      F1005EC7F2005DC8F200B4E3F8003F8FC6003C92CF00C0F3FF0071DAFB0074DB
      FB0075DBFC0076DCFC0073DAFA00449CD400378CCB00368CCB00358CCC00348D
      CC003890CE003D92CF00B9F4FF0073DBFB006BCCF2006CCDF3006CCEF3006DCE
      F300479CD40056BAE900D7F6FF00D6F6FF00D5F6FF00DBFCFF003E94D000ABF0
      FF00449DD600378BCB005CBEEA006FD9FB006AD6FA0068D5F90067D4F90066D4
      F90082DEFC00AAE0F6003885BC004095D0008AD7F50044A1D800DDFDFF00DAFA
      FF00DEFAFF0074DCFC0076DBFA0075DAFA0074DAFA0072D9FA00A1E8FF007CBF
      E6004296D1006BBEE8006DBDE600BBF2FF0075DEFD0077DEFC0078DEFC007BDF
      FC007DDFFC007CDFFC0080E0FD00ADF0FF004D9DD3004FA6D9008EDAF500A2EE
      FF0082E5FE0084E5FE0085E6FE0084E6FE0096EBFF008CD8F5003985BC004499
      D2003F94D000ABFBFF009BF3FF0092F1FF0093F1FF00A6F8FF0065B8E3004598
      D1004094D0003E92CF003E92CE003F92CE003F93CF004194CE00000000000000
      0000000000000000000000000000000000000000000000000000F985FAFBFCFD
      FDFDFDFDFDFDFEFF0000F1F2F3F4F5F6F6F6F6F6F6F6F7F8000085E7E8E9EAEB
      EBECECECECEDEEEFF000DADBDCDDDEDFE0E1E2E2E2E3E4E5E600CDCECFD0D18B
      D2D3D4D5D6D6D7D8D900C0C1C2AFAFAFC3C4C5C6C7C8C9CACBCCB3B4B5B6B7B8
      B9BABB94BCBDBE8FBFC0A6A7A8A9AAAAABACADAEAFB0B1B286858E9A9B9C9D9B
      9E9FA0A1A2A3A486A5008E8F909192939494959696979899000086898A8A8B8C
      8D878787878E8685000085868787868800000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000}
    ParentFont = False
    TabOrder = 2
    DoBrowse = False
    Filter = 'Zip Archive |*.zip|'
    BrowseStyle = fbFolder
  end
  object MSListBox1: tMSListBox
    Left = 8
    Top = 16
    Width = 137
    Height = 45
    ParentCustomHint = False
    BevelKind = bkTile
    BorderStyle = bsDialog
    Color = clBtnFace
    Font.Charset = ANSI_CHARSET
    Font.Color = clWindowText
    Font.Height = -11
    Font.Name = 'Tahoma'
    Font.Style = []
    ItemHeight = 13
    Items.Strings = (
      'Extract Zip Archive'
      'Compress Single File'
      'Compress Folder')
    ParentFont = False
    ParentShowHint = False
    ShowHint = False
    TabOrder = 0
    Text = 'Extract Zip Archive'#13#10'Compress Single File'#13#10'Compress Folder'#13#10
    SelectedIndex = 0
  end
  object MainMenu: tMSMainMenu
    object MenuItem1: tMSMenuItem
      Caption = '&Extract'
    end
  end
end
EndDialog>Dialog1

AddDialogHandler>Dialog1,,OnClose,Exit
AddDialogHandler>Dialog1,MSListBox1,OnClick,SetZipOrCompressOption
AddDialogHandler>Dialog1,MSButton1,OnClick,DoInputBrowse
AddDialogHandler>Dialog1,MSButton2,OnClick,DoOutputBrowse
AddDialogHandler>Dialog1,Edit1,OnDblClick,DoInputBrowse
AddDialogHandler>Dialog1,Edit2,OnDblClick,DoOutputBrowse
AddDialogHandler>Dialog1,MenuItem1,OnClick,ZipFunction

SetDialogProperty>Dialog1,,BorderIcons,[biSystemMenu, biMinimize]
Show>Dialog1
//Hide 2nd instance when compiled
GetWindowHandle>Simple Zip & Extract,hIEWnd
LibFunc>user32,SetParent,r,hIEWnd,DIALOG1.HANDLE
LibFunc>user32,SetWindowLongA,sres,hIEWnd,-16,524288
LET>APP_TITLE=Simple Zip & Extract App
GoSub>LoadVBScript

Label>ActionLoop
Wait>.1
GetDialogProperty>Dialog1,Edit1,Text,InputRes1
GetDialogProperty>Dialog1,Edit2,Text,InputRes2
IF>{(%InputRes1%="")OR(%InputRes2%="")}
SetDialogProperty>Dialog1,MenuItem1,Enabled,False
ELSE
SetDialogProperty>Dialog1,MenuItem1,Enabled,True
ENDIF
Goto>ActionLoop



SRT>ZipFunction
  GetDialogProperty>Dialog1,Edit1,Text,InputStr
  GetDialogProperty>Dialog1,Edit2,Text,OutputStr
  GetDialogProperty>Dialog1,MSListBox1,SelectedIndex,Res
  //Unzip function
  IF>Res=0
    VBEval>UnzipFile("%InputStr%","%OutputStr%"),res
  ENDIF
  
  //Zip Single file function
  IF>Res=1
    Pos>.zip,%OutputStr%,1,DotZipPos
    IF>DotZipPos=0
      Let>OutputStr=%OutputStr%.zip
    ENDIF
    VBEval>CompressFile("%InputStr%","%OutputStr%"),res
  ENDIF

  //Zip Content of a folder function
  IF>Res=2
    //<--Start Check if source folder and sub folders are empty
    Let>RP_WAIT=1
    Let>RP_WINDOWMODE=0
    RunProgram>cmd /C DIR /AD/B/OS/S %InputStr% > %TEMP_DIR%~temp_dir_listing.txt
    Let>RP_WAIT=0
    Let>WaitReay=False
    Repeat>WaitReay
      Wait>0.1
      IfFileExists>%TEMP_DIR%~temp_dir_listing.txt
        ReadFile>%TEMP_DIR%~temp_dir_listing.txt,DirRes
        Separate>%DirRes%,CRLF,DirList
        DeleteFile>%TEMP_DIR%~temp_dir_listing.txt
        Let>WaitReay=True
      Endif
    Until>WaitReay,True

     IF>DirList_Count>0

       Let>DirCounter=0
       Repeat>DirCounter
         Add>DirCounter,1
         Let>DirToCheck=DirList_%DirCounter%
         'mdl>DirToCheck
         Let>GFL_TYPE=1
         GetFileList>%DirToCheck%\*.*,FoldersRes
         Let>GFL_TYPE=0
         Separate>%FoldersRes%,;,Folder_Names
         IF>Folder_Names_Count=0
           GetFileList>%DirToCheck%\*.*,FilesRes
           Separate>%FilesRes%,;,File_Names
           //Create an empty desktop.ini file if the folder is empty
           IF>File_Names_Count=0
             WriteLn>%DirToCheck%\desktop.ini,WrtLn,
           ENDIF
         ENDIF
       Until>DirCounter,DirList_Count

         //Compress Folder and sub Folder content
         Pos>.zip,%OutputStr%,1,DotZipPos
         IF>DotZipPos=0
           Let>OutputStr=%OutputStr%.zip
         ENDIF
         VBEval>CompressFolder("%InputStr%","%OutputStr%"),res

     ELSE
       //There are no sub folder. Let's check if the folder is empty.
       GetFileList>%InputStr%\*.*,FilesRes
       Separate>%FilesRes%,;,File_Names
       IF>File_Names_Count=0
         LibFunc>user32,MessageBoxA,res,0,The folder you are trying to compress is empty.%CRLF%%CRLF%No action is takes.,Simple Zip & Extract App,270384
       ELSE
         //Compress Folder content
         Pos>.zip,%OutputStr%,1,DotZipPos
         IF>DotZipPos=0
           Let>OutputStr=%OutputStr%.zip
         ENDIF
         VBEval>CompressFolder("%InputStr%","%OutputStr%"),res
       ENDIF

     ENDIF
    //<--End Check if source folder and sub folders are empty
  ENDIF
END>ZipFunction



SRT>SetZipOrCompressOption
  GetDialogProperty>Dialog1,MSListBox1,SelectedIndex,Res
  IF>Res=0
    SetDialogProperty>Dialog1,Label1,Caption,Zip Archive to Extract
    SetDialogProperty>Dialog1,Label2,Caption,Output Directory
    SetDialogProperty>Dialog1,MSButton1,BrowseStyle,fbOpen
    SetDialogProperty>Dialog1,MSButton1,Filter,Archive (*.zip)|*.zip|
    SetDialogProperty>Dialog1,MSButton2,Filter,Zip Archive|*.zip|
    SetDialogProperty>Dialog1,MSButton2,BrowseStyle,fbFolder
    SetDialogProperty>Dialog1,MenuItem1,Caption,Extract
    SetDialogProperty>Dialog1,Edit1,Text,
    SetDialogProperty>Dialog1,Edit2,Text,
  ENDIF

  IF>Res=1
    SetDialogProperty>Dialog1,Label1,Caption,File to Compress
    SetDialogProperty>Dialog1,Label2,Caption,Output Directory and Name
    SetDialogProperty>Dialog1,MSButton1,BrowseStyle,fbOpen
    SetDialogProperty>Dialog1,MSButton1,Filter,All Files (*.*)|*.*|
    SetDialogProperty>Dialog1,MSButton2,Filter,Zip Archive|*.zip|
    SetDialogProperty>Dialog1,MSButton2,BrowseStyle,fbSave
    SetDialogProperty>Dialog1,MSButton2,FileName,Archive Name.zip
    SetDialogProperty>Dialog1,MenuItem1,Caption,Compress
    SetDialogProperty>Dialog1,Edit1,Text,
    SetDialogProperty>Dialog1,Edit2,Text,
  ENDIF

  IF>Res=2
    SetDialogProperty>Dialog1,Label1,Caption,Folder Content to Compress
    SetDialogProperty>Dialog1,Label2,Caption,Output Directory and Name
    SetDialogProperty>Dialog1,MSButton1,BrowseStyle,fbFolder
    SetDialogProperty>Dialog1,MSButton2,Filter,Zip Archive|*.zip|
    SetDialogProperty>Dialog1,MSButton2,BrowseStyle,fbSave
    SetDialogProperty>Dialog1,MSButton2,FileName,Archive Name.zip
    SetDialogProperty>Dialog1,MenuItem1,Caption,Compress
    SetDialogProperty>Dialog1,Edit1,Text,
    SetDialogProperty>Dialog1,Edit2,Text,
  ENDIF
END>SetZipOrCompressOption



SRT>DoInputBrowse
  SetDialogProperty>Dialog1,MSButton1,DoBrowse,True
  GetDialogProperty>Dialog1,MSButton1,Filename,strFileName
  SetDialogProperty>Dialog1,Edit1,Text,strFileName
  GetDialogProperty>Dialog1,MSListBox1,SelectedIndex,Res
  IF>strFileName<>
    IF>Res=0
      //Check if file extension (.zip) exists
      Pos>.zip,%strFileName%,1,DotZipPos
      IF>DotZipPos=0
        Let>strFileName=%strFileName%.zip
      ENDIF
    ENDIF
  SetDialogProperty>Dialog1,Edit1,Text,strFileName
  Endif
END>DoInputBrowse



SRT>DoOutputBrowse
  SetDialogProperty>Dialog1,MSButton2,DoBrowse,True
  GetDialogProperty>Dialog1,MSButton2,Filename,strFileName
  SetDialogProperty>Dialog1,Edit2,Text,strFileName
  IF>strFileName<>
    IF>Res=1
      //Check if file extension (.zip) exists
      Pos>.zip,%strFileName%,1,DotZipPos
      IF>DotZipPos=0
        Let>strFileName=%strFileName%.zip
      ENDIF
    ENDIF

    IF>Res=2
      //Check if file extension (.zip) exists
      Pos>.zip,%strFileName%,1,DotZipPos
      IF>DotZipPos=0
        Let>strFileName=%strFileName%.zip
      ENDIF
    ENDIF
  SetDialogProperty>Dialog1,Edit2,Text,strFileName
  Endif
END>DoOutputBrowse



SRT>LoadVBScript
VBSTART
'Unzip file function
Function UnzipFile(ZippedFile,OutputDir)
'The location of your zip file.
ZipFile = ZippedFile
'The folder the contents should be extracted to.
ExtractTo = OutputDir
'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
End Function

'Compress file function
Function CompressFile(SourceFile,TargetFile)
Const FOF_SIMPLEPROGRESS = 256
Dim MySource, MyTarget, MyHex, MyBinary, i
Dim oShell, oCTF
Dim oFileSys
dim winShell
'The location of the file to compress
MySource = SourceFile
'The location of the zip file
MyTarget = TargetFile
MyHex = Array(80, 75, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)

For i = 0 To UBound(MyHex)
MyBinary = MyBinary & Chr(MyHex(i))
Next

Set oShell = CreateObject("WScript.Shell")
Set oFileSys = CreateObject("Scripting.FileSystemObject")
'Create a zip file.
   Set oCTF = oFileSys.CreateTextFile(MyTarget, True)
   oCTF.Write MyBinary
   oCTF.Close
   Set oCTF = Nothing
'Add Source File to zip.
   set winShell = createObject("shell.application")
   winShell.namespace(MyTarget).CopyHere MySource
End Function

'Compress folder function
Function CompressFolder(SourceFolder,TargetFile)

Const ForReading = 1, ForWriting = 2, ForAppending = 8

Dim MySource, MyTarget, MyZipName, MyHex, MyBinary, i
Dim oShell, oApp, oFolder, oCTF, oFile
Dim oFileSys
'The location of the folder to compress
MySource = SourceFolder
'The location of the zip file
MyTarget = TargetFile

MyHex = Array(80, 75, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0)

For i = 0 To UBound(MyHex)
MyBinary = MyBinary & Chr(MyHex(i))
Next

Set oShell = CreateObject("WScript.Shell")
Set oFileSys = CreateObject("Scripting.FileSystemObject")

'Create a zip file.
Set oCTF = oFileSys.CreateTextFile(MyTarget, True)
oCTF.Write MyBinary
oCTF.Close
Set oCTF = Nothing

Set oApp = CreateObject("Shell.Application")

'Add Source Folder to zip.
Set oFolder = oApp.NameSpace(MySource)
If Not oFolder Is Nothing Then
oApp.NameSpace(MyTarget).CopyHere oFolder.Items
End If

Set oFile=Nothing
Set oFileSys=Nothing
End Function
VBEND
END>LoadVBScript



SRT>Exit
  Exit>1
END>Exit

User avatar
JRL
Automation Wizard
Posts: 3500
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Fri Mar 29, 2013 8:52 pm

VERY cool!
I somehow broke the standard Windows zip/unzip. This is simple enough for even me to use.

Thank you for sharing.

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1348
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Post by Dorian (MJT support) » Mon Apr 01, 2013 11:16 pm

Wow, that really is awesome. I'm adding it to the thread of the month competition entries. Very clever indeed!!
Yes, we have a Custom Scripting Service. Message me or go here

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Tue Apr 02, 2013 1:20 pm

Thanks JRL and Parsnipnose3000...I'm glad you like it. :)

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts