ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE. Software > Coding Snacks

Tiny batch file: zips current directory, date+time stamps, moves to parent


Just thought I'd share this little code snippet for a batch (zipcurdir.bat) file that I use quite frequently.
Requires 7-zip but could be adapted for any other zip tool.
Then just put this little .bat file in any directories where you want to be able to super quickly make a uniquely timestamped zip file of the contents of the directory, and then move the zip file out of the way to the parent directory.
I use this all the time when I'm working on a project and it's not under version control and I want to make sure I have quick backups before something goes wrong.

Add any exclusion patterns you want to the extraoptions line, and change 7-zip location if different; or maybe you want to change the destination folder..

--- ---for %%a in ("%cd%") do set "CurDir=%%~na"
set thedir=%CurDir%

set mydate=%date:~12,2%%date:~4,2%%date:~7,2%
set HOUR=%TIMEZERO:~0,2%
set MIN=%TIMEZERO:~3,2%
set mytime=%HOUR%%MIN%
set zformat=zip

set extraoptions=-xr!Temp -xr!Junk

set zcmd="c:\program files\7-zip\7z" a -t%zformat% -r %extraoptions%
set fname=%thedir%_%mydate%_%mytime%.%zformat%

echo %zcmd% ..\%fname% .\
%zcmd% ..\%fname% .\

As an example if I put this zipcurdir.bat file in my Documents\Arduino\ folder and run it, I get the file in the parent directory: ""

The only thing neat about this batch file is the autonaming of the created file based on the current directory and the fact that you never have to modify the batch file no matter where you put it.

Handy! I have some similar "lazy version control" habits, for example to clone some single work in progress file with a timestamp suffix (via autohotkey and FARR, of course ;D). For when strict VC is too much but you still want to avoid the "file.ext", "file - copy.ext", "file -copy(2) final.ext" mess.

Seems very interesting !!!!!!!
 :-* :P


[0] Message Index

Go to full version