BATCH Zip files in placeIn this case we are using 7zip command line version to compress files in place.
WHAT IS INPLACE COMPRESSION? If I have some files c:\files\file1.txt c:\files\file2.txt c:\files\folder1\file1.txt c:\files\folder2\file2.txt It will compress them and leave them as c:\files\file1.txt.7z c:\files\file2.txt.7z c:\files\folder1\file1.txt.7z c:\files\folder2\file2.txt.7z WHY WOULD YOU WANT TO DO THIS? 1. running low on HD space 2. you want to archive data onto DVDs ADVANTAGES 1. preserve folder structure 2. for DVD archival, zipping everything into 1 big file is a bad idea. if the disc gets the smallest scratch and one byte is unreadable it screws the integrity of the entire disc. If you zip everything in place, if one file gets corrupted, it doesn't effect any of the other files. DESCRIPTION This windows batch file, zips files in place with 7zip command line with maximum compression, then erases the original. zip_files_inplace.bat @echo off REM -------MAIN-------------------------------- FOR %%A in (.) do SET CWD=%%~fA SET IGNORE1=%CWD%\7z.dll SET IGNORE2=%CWD%\7z.exe SET IGNORE3=%CWD%\unzip_files_inplace.bat SET IGNORE4=%CWD%\zip_files_inplace.bat FOR /R %%A in (*.*) do call :processFilename %%A GOTO:EOF REM -------MAIN-------------------------------- REM ------------------------------------------- :processFilename set FILENAME=%* IF %FILENAME%==%IGNORE1% GOTO:EOF IF %FILENAME%==%IGNORE2% GOTO:EOF IF %FILENAME%==%IGNORE3% GOTO:EOF IF %FILENAME%==%IGNORE4% GOTO:EOF 7z a -mx9 "%FILENAME%.7z" "%FILENAME%" erase "%FILENAME%" GOTO:EOF REM ------------------------------------------- Notes: * if you only want to compress '.txt' files change *.* to *.txt in the batch file * Requires 7z.dll and 7z.exe to be in the same folder as zip_files_inplace.bat. * 7z.dll and 7z.exe files can be downloaded as a part of the 7zip package. Tags: batch | Related Articles |