Last updated on This guide demonstrates how to automate repetitive compression tasks using batch files with two popular free archiving tools, the command-line utility for (freeware) and the standalone console version of (7-Zip Extra: standalone console version). For using the WinRAR command-line tools, see.Automating compression tasks using batch files or other scripting languages makes it simple and fast to compress, copy, rename, and move files from the same folder(s) when it’s necessary to do so on a regular basis.This guide covers the use of two free archiving utilities, the command-line add-on utility for IZArc and the standalone console version for 7-Zip. Using either of these utilities to automate archiving needs is fairly easy to do, costs nothing, and saves time. Although this guide is designed to enable the user to accomplish this task quickly and easily, it is assumed that the reader is already familiar with creating and using batch files and has some experience with using compression utilities. WinXP was used to verify the information in this guide. Download one of the following (32 bit versions were used for this guide).
the 7-Zip standalone console version from the. the IZArc utility and the IZArc command-line Add-On from theThe versions used for this guide were: 7-Zip ver 18.01 (2018-01-28) for Windows:, IZArc Version 4.1, and IZArc command-line Add-On Version 1.1.Note: This guide uses the standalone console version of 7-Zip (7za.exe), which supports only the 7z, cab, zip, gzip, bzip2, Z and the tar formats, and unpacks Z, lzma, CAB formats. The full version of 7-Zip (installable and portable versions) contains a command-line executable (7z.exe) that supports additional formats and is explained in the 7-Zip help files.The IZArc command-line utility creates ZIP, CAB, LHA, BH, JAR, TAR, TGZ, and TBZ formats, and extracts ZIP, RAR, ARJ, CAB, LHA(LZH), ARC, ACE, GZIP, BZIP2, TAR (TGZ, TBZ2), UUE, ZOO, JAR formats.
The directory hierarchy is yearly parent folders with monthly sub-folders that each contain multiple zip files. What I need is a batch file that I can run from any yearly folder that will open each monthly folder, unzip the files, then move to the next monthly file until the entire year's worth of data has been uncompressed. Windows built-in command compact allows one to compress or un-compress files on a NTFS file system. Using this command we can set compression attributes on a directory also so that the new files added to the directory will be compressed automatically.Let’s see the syntax of the command ‘compact’ with few examples.
For IZArc, the command-line executables are izarcc for the compression function and izarce for the extraction function.Step 2. Install the utilityFor 7-Zip:Extract the 7-Zip standalone console version to a location of your choice, e.g., C:7zipCL or C:Program Files7zipCL.For IZArc:Extract the IZArc command-line Add-on to a location of your choice or to the default location (e.g., C:Program FilesIZArc). Test the installation (optional)Open a CMD window by hitting the Start button, enter “cmd” and press “OK”. Use cd to navigate to the 7-Zip and/or IZArc installation folders and execute the following:For 7-Zip:Type “7za” and then press ENTER.
If working correctly, you should see the usage commands for 7-zip as shown in the top left thumbnail (click the picture to enlarge):For IZArc:Type “izarcc” and then press ENTER. If working correctly, you should see the usage commands for IZArc as shown in the top right thumbnail (click the pictures to enlarge and view content). IZArc Command Screen 7Zip Command ScreenStep 4. Create/modify batch file(s)For the sake of simplicity and to focus on quickly demonstrating the use of these two compression utilities, this guide includes two simple example batch files (one for IZArc and another for 7Zip) that compresses all files from a folder into a single zip archive with a unique date suffix, moves the zip archive to another folder, and optionally deletes the original files. For both batch files, the folder “zipdir” contains the files to zip and the folder “movedir” is where the completed archives are moved.Depending on which utility you wish to use, click one of the following links to open the batch file text in a new window where you can cut and paste it into your text editor or download it: (IZArc) and/or ( 7-Zip).
Here is a batch file to use 7-Zip to create Individual ZIP files from a large list of files in a directory. I found this useful for zippingROM or other files for emulators as 7-Zip doesn't have this functionality built in.Requirements - 7-Zip.
I've used the64bit version for this so if you use the 32bit version or have installed 7-Zip into a different directory then replacec:Program Files7-Zip with the path where 7z.exe is installed.Open notepad (or similar) and paste in the following code:@ECHO OFFFOR%%i IN (.) DO (ECHO '%%i' FIND /I 'zip.bat' 1NUL) ('c:Program Files7-Zip7z.exe' a -tzip '%%ni.zip' '%%i'if%ERRORLEVEL% 0 del '%%i'))Then save the file as 'zip.bat'. Put zip.bat into the directory with the files you want to individually ZIP and double click on zip.bat to run.Breakdown of the Batch file is as follows:@ECHO OFFHides echo of the batch commands, @ before ECHO means don't output OFF as wellFOR%%i IN (.) DO (For each file in directory (.) DO the following command(s) -%i loaded with the filenameECHO '%%i' FIND /I 'zip.bat' 1NUL) (If filename (%i) is zip.bat do nothing, else'c:Program Files7-Zip7z.exe' a -tzip '%%ni.zip' '%%i'Run 7z.exe for each filename. Options - a=archive, -tzip=create ZIP archive%ni=take filename minus extension - e.g. For a file 'rom.bin' the command will bec:Program Files7-Zip7z.exe a -tzip rom.zip rom.binif%ERRORLEVEL% 0 del '%%i'If ZIP successful then delete original file, remove this line if you don't want to delete the originalsAdditional% used in filename variables%%i &%%ni is required for the batch file only and would be omitted if thiswas run from the command line.
Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
March 2023
Categories |