ZIP & UNZIP (Windows)Generally, you can use for instance 7-zip to zip or unzip files (via Shell command)
(program C:\Program Files (x86)\7-Zip\7z.exe or C:\Program Files\7-Zip\7z.exe)
But here we use PowerShell included in Windows.
Same samples of possible situations.
Of course you need to use your own file names and directories.
'---1--- ZIPPING A SINGLE FILE
ZIPTOCREATE$ = "D:\TEMP\TESTMAKING.ZIP"
MYFILE$ = "D:\CZUR\SV0010_Janvier_1914.pdf"
UU$ = "powershell Compress-Archive -force -path " + Chr$(34) MYFILE$+ Chr$(34) + " " + Chr$(34) + ZIPTOCREATE$ + Chr$(34)
Shell UU$
'Note -force overwrite existing ZIP. You can use -update to refresh the ZIP
End
'---2--- ZIPPING MULTIPLE FILES
ZIPTOCREATE$ = "D:\TEMP\TESTMAKING.ZIP"
FILE1$ = "D:\CZUR\SV0010_Janvier_1914.pdf"
FILE2$ = "D:\CZUR\SV0011_FĂ©vrier_1914.pdf"
UU$ = "powershell Compress-Archive -force -path " + Chr$(34) + FILE1$ + Chr$(34) + "
, " + Chr$(34) + FILE2$ + Chr$(34) + " " + Chr$(34) + ZIPTOCREATE$ + Chr$(34)
Shell UU$
End
---3--- ZIPPING MULTIPLE FILES with ' * '
ZIPTOCREATE$ = "D:\TEMP\TESTMAKING.ZIP"
FILEZ$ = "D:\CZUR\*.pdf" : ' We want here to zip all pdf file located in CZUR directory
UU$ = "powershell Compress-Archive -force -path " + Chr$(34) + FILEZ$ + Chr$(34) + " " + Chr$(34) + ZIPTOCREATE$ + Chr$(34)
Shell UU$
End
'---4--- ZIPPING A DIRECTORY WITH THE ROOT
REPERTOIREACOPIER$ = "D:\CZUR\MYFILES" ' (don't add \ at the end of the path)
ZIPTOCREATE$ = "D:\TEMP\TESTMAKING.ZIP"
UU$ = "powershell Compress-Archive -force " + Chr$(34) + REPERTOIREACOPIER$ + Chr$(34) + " " + Chr$(34) + ZIPTOCREATE$ + Chr$(34)
Shell UU$
end
'---5--- ZIPPING A DIRECTORY WITHOUT THE ROOT
REPERTOIREACOPIER$ = "D:\CZUR\MYFILES\*" ' ( add \* at the end of the path)
ZIPTOCREATE$ = "D:\TEMP\TESTMAKING.ZIP"
UU$ = "powershell Compress-Archive -force " + Chr$(34) + REPERTOIREACOPIER$ + Chr$(34) + " " + Chr$(34) + ZIPTOCREATE$ + Chr$(34)
Shell UU$
'Note: the zip file created has not information about "myfiles" directory
end
'---6---UNZIPPING
DESTINATIONDIRECTORY$ = "D:\CZUR\tempo"
ZIPTOUNZIP$ = "D:\CZUR\livre.ZIP"
UU$ = "powershell Expand-Archive -force " + Chr$(34) + ZIPTOUNZIP$ + Chr$(34) + " " + Chr$(34) + DESTINATIONDIRECTORY$ + Chr$(34)
Shell UU$
' if TEMPO directory do not exist, it will be created (due to -force option)
End
Please read for more informations:
'
https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.archive/compress-archive?view=powershell-7.2'
https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.archive/expand-archive?view=powershell-7.2