topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Tuesday May 17, 2022, 11:25 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Tiny batch file: zips current directory, date+time stamps, moves to parent  (Read 253 times)

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,768
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
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 TIMEZERO=%TIME: =0%
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: "Arduino_220506_0615.zip"

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.

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,142
    • View Profile
    • Donate to Member
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.

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,836
    • View Profile
    • Donate to Member
Seems very interesting !!!!!!!
 :-* :P