In Windows you can zip some files by
right click → Send to → Compressed (zipped) folder
And unzip by double clicking on the .zip
file and extract the files.
Is there a way to apply those abilities from a script (.bat file) without the need to install any third-party software?
Right-click the file you want to zip, and then select Send to > Compressed (zipped) folder. Open File Explorer and find the zipped folder. To unzip the entire folder, right-click to select Extract All, and then follow the instructions. To unzip a single file or folder, double-click the zipped folder to open it.
Windows 10 comes with native support for files compression and uncompression using which you can easily compress(zip) and uncompress (unzip) files or folders on your Windows computer.
Now, you need to create a batch file for zipping a folder. To do that, open the Notepad app and enter a script like below: echo on for /f "tokens=3,2,4 delims=/- " %%x in ("%date%") do set d=%%y%%x%%z set data=%d% Echo zipping... "C:\Program Files\7-Zip\7z.exe" a -tzip "C:\twc. zip" "C:\MyDocuments\*.
To expand upon Steven Penny's PowerShell solution, you can incorporate it into a batch file by calling powershell.exe
like this:
powershell.exe -nologo -noprofile -command "& { Add-Type -A 'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::ExtractToDirectory('foo.zip', 'bar'); }"
As Ivan Shilo said, this won't work with PowerShell 2, it requires PowerShell 3 or greater and .NET Framework 4.
If you have Java installed, you can compress to a ZIP archive using the jar
command:
jar -cMf targetArchive.zip sourceDirectory
c = Creates a new archive file.
M = Specifies that a manifest file should not be added to the archive.
f = Indicates target file name.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With