7-zip compress full paths from directory listing
7-zip is a great free tool for compressing files, but it lacks the feature for preserving the absolute path of the source files in the archive.
The following batch script will trim the trailing drive letters from a directory listing.
The example below lists files that have changed since a specific date. But to get a full listing, just use dir /s /b > filelist.txt
.
@echo off
REM -- you need this for dynamic variables
setlocal ENABLEDELAYEDEXPANSION
REM -- date since files have changed
set Since=11/25/2010
REM -- root path for the data being archived as well as for the 7z file in this case
set MyAppPath=C:\Inetpub\wwwroot\PDF
REM -- change active directory to root so 7z will like the listing
cd /d C:\
REM -- generate file list
Forfiles -p %MyAppPath% /s /m *.* /D %Since% /C "cmd /C echo @path>>%MyAppPath%\filelist.txt"
REM -- take all lines from filelist.txt, crop down the trailing drive letter and add a " in front
REM -- then execute 7z with the result; 7z will use store compression in this case.
for /f "tokens=* delims= " %%a in (%MyAppPath%\filelist.txt) do (
set PDFPath=%%a
"c:\program files\7-zip\7z.exe" a -t7z -mx0 %MyAppPath%\archive.7z ^"!PDFPath:~4,-1!
)
del filelist.txt
Originally posted to: http://www.thesysadminhimself.com/2010/12/7-zip-compress-full-paths-from.html
Comments