2

For EDI files which need to be archived, I would like to use a compression utility (like 7Zip) which collects and compresses files based on their file date. For example, a weekly archive (incoming-2009-01.7z for week 1) needs to be updated with all incoming files whose file date is in this week.

Is there a command line utility which can be used to invoke a compression tool with the necessary arguments, or an other easy way to implement such an archive strategy?

2 Answers 2

4

I don't know of a utility that provides this directly but it's fairly straightforward to build a script (using powershell, perl, python ..) to identify the files that meet your criteria, drop the fully qualified names (e.g. d:\incoming\something\filename.ext ) into a flat text file, one file name per line and then have your compression utility create an archive from that list file e.g.

7z -a output.zip @filelist.txt

If you wrap the whole thing inside the script then it's trivially easy to assign the type of archive names that you specified.

Added a Powershell example.

$archiveroot="c:\temp"
$oldest = (get-date) - (new-timespan -day 31)
$archivename="Incoming-" + $oldest.year + "-" +$oldest.month+".7z"
$filelist= get-childitem $archiveroot -recurse | where-object {$_.lastwritetime -gt $oldest}
$filelist | format-table -hideTableHeaders FullName | out-file -encoding utf8 -filepath lastmonthsfiles.txt
& .\7z.exe a $archivename `@lastmonthsfiles.txt

It's not quite a one liner, you will need to point it properly at the 7-Zip exe, add some parameter handling, some logging\error handling and it should clean up the working files but it's a pointer in the right direction.

0
1

I use a script made up from different sources..

rd /s /q f:\todays

rem This makes a backup of the previous days data, 

    robocopy u:\  F:\todays\u-Drive /mir /w:0 /r:0 /e /s /np /fft /maxage:1 /maxlad:1 /xf *.pst

rem zips up the backup folder

    7z a -tzip todays "todays\*" -r


rem renames the zip file to a date stamp

    Set CURRDATE=%TEMP%\CURRDATE.TMP
    Set CURRTIME=%TEMP%\CURRTIME.TMP
    DATE /T > %CURRDATE%
    TIME /T > %CURRTIME%
    Set PARSEARG="eol=; tokens=1,2,3,4* delims=/, "
    For /F %PARSEARG% %%i in (%CURRDATE%) Do SET YYYYMMDD=%%l%%k%%j
    Set PARSEARG="eol=; tokens=1,2,3* delims=:, "
    For /F %PARSEARG% %%i in (%CURRTIME%) Do Set HHMM=%%i%%j%%k


    RENAME todays.zip backup_%YYYYMMDD%%HHMM%.zip


    move /y F:\*.zip F:\backup\Zips

I use 7zip and robocopy. Place both exe file in the same dir as the script.

How it works:

It deletes the previous days 'todays' folder as we want a clean slate, then robocopy scans the data folder (U:) and its set to only copy those files created or modified in the last 24hrs. It copies it to another drive/folder (F:\todays). This give you the incremental files.

7zip then compresses that folder

the next script works out the year, month, day, hours, minutes, seconds which then renames the zip file made under 7zip.

Finally the script moves the renamed zip to another folder called 'zips.

I have been using this script form many years to give me daily zip files which can quickly be opened from explorer .

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .