Batch to zip folder

October 5, 2018 at 19:24:17
Specs: Windows 10
I am trying to create a backup of my daily work.

Is there a way to create a batch file to zip a folder with date and time and move it to specific location.

Thanks in advance

message edited by Arshath

See More: Batch to zip folder

Reply ↓  Report •

October 6, 2018 at 11:30:56
The specific commands to handle zipping will depend on what tools you use. For Info-ZIP:

@echo off & setlocal enableextensions
for /f "tokens=1-3 delims=./-" %%f in ("%date%") do set today_=%%h%%f%%g
for /f "tokens=1-3 delims=:. " %%i in ("%time%") do set now_=%%i%%j%%k
zip -roq9T *.*
move "%destination%"

This assumes US-style dates (mm/dd/yyyy); for European-style (dd/mm/yyyy) swap %%f and %%g.

The switches for zip:
-r Recurse directories.
-o Set the zip file's timestamp equal to the newest file zipped.
-q Quiet. (No output.)
-9 Best compression.
-T Test zipfile integrity.

(For other implementations of zip, see the program's docs.)

Replace %destination% with the full path where you want the zip moved to.

Reply ↓  Report •

October 8, 2018 at 03:01:02
First of all what zipping program are you using?
7-zip, winzip or winrar?

For 7-zip (tested on a win 10 machine and can confirm it works):

Swap %%b and %%a if you want american-style date, currently it will set the date to europea-style.
Run from the folder you want to be backed-up, the .zip file will be placed on the desktop,
but you can change "%USERPROFILE%\Desktop" to any directory you want...

@echo off&set "launchdir=%~dp0"
for /f "tokens=2-4 delims=/ " %%a in ("%date%") do set "today=%%b-%%a-%%c"
for /f "tokens=1-3 delims=:" %%1 in ("%time:~0,-3%") do set "now=%%1-%%2-%%3"
set ""
for /f "tokens=*" %%a in ('dir/b') do (
if not "%~nx0"=="%%a" (
"C:\Program Files\7-Zip\7z.exe" a "%zipfile%" "%%a"
move "%zipfile%" "%USERPROFILE%\Desktop"

i5-6600K[delid]@4.7GHz/4.3GHz@1.376v LLC=6 | 2x4GB Crucial-DDR4-2133CL15@14-14-14-28 1T 2800MHz@1.35v
MSI Armor RX 570 4GB@1260Mhz core@1.000v/2000MHz

Reply ↓  Report •
Related Solutions

Ask Question