Search code examples
batch-file7zip

Use 7zip to include files with *current date* only


I'm creating then zipping a file that is stamped with the current date with 7-zip. I am able to use the following switch to create the zip file to add to:

7z -tzi C:\RACHAEL\my_work\dbs\MyDb\%DATE:~11,4%\%DATE:~5,2%\MyDb_bak_%DATE:~11,4%-%DATE:~5,2%-%DATE:~8,2%.bak.zip 

but adding the "-i!" command does not locate the file specfied

 7z -tzi C:\RACHAEL\my_work\dbs\MyDb\%DATE:~11,4%\%DATE:~5,2%\MyDb_bak_%DATE:~11,4%-%DATE:~5,2%-%DATE:~8,2%.bak.zip -i!C:\RACHAEL\my_work\dbs\MyDb_bak_<get_current_date_in_correct_format>.bak 

How would one achieve locating the file in this directory containing the current formatted date from a batch file? Is there an escape character? The '%' does not provide this purpose in 7zip, which I assumed it would.

Thanks in advance!


Solution

  • was missing the escape character ^ before the path I was trying to add to the successfully zipped directory created with 7zip.

    This is the corrected statement:

    echo Using 7-zip to compress today's backup folder...
    7z a -tzip C:\RACHAEL\my_work\dbs\MyDb\%DATE:~11,4%\%DATE:~5,2%\MyDb_bak_%DATE:~11,4%-%DATE:~5,2%-%DATE:~8,2%.bak.zip -i!^C:\RACHAEL\my_work\dbs\MyDb\%DATE:~11,4%\%DATE:~5,2%\MyDb_bak_%DATE:~11,4%-%DATE:~5,2%-%DATE:~8,2%.bak
                                                                                                                             ^missing escape character right here so that path could actually be parsed per date format.