Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

From 7zip I've downloaded their command line tool 7za.exe, and I have to following script:

echo off


set zip ="C:\7za.exe"

set filename=""

set pathtobackup="C:\MyDocs"

%zip% -t7z %filename% %pathtobackup%\*.doc

My intention is to backup all the doc files in MyDocs folder (including subfolders) and put them in a dated zip file. Afterwards I will move this file with robocopy to my server, but at the moment Im having some problems getting it to zip the files.

Anyone have a clue? Anyway I can append a password for the file too?

share|improve this question
You're "having some problems": care to elaborate? At a first glance, you're creating a .7z archive with a .zip extension. Also, you're relying on the %date% variable which may contain invalid, reserved characters. – and31415 Mar 5 '14 at 9:54
up vote 2 down vote accepted

Use the syntax

7z a -tzip -r src\*.cpp src\*.h

so in your case, it'd be

7z a -t7z %filename% -r %pathtobackup%\*.doc


share|improve this answer

Install 7z and you can use this working example with delete script for files older than 7 days. What this script does, it zips the files from given 'input' folder to 'output' folder. In order to zip folders, you have to add /d or to zip all files within folder just modify the last "%%X".

REM This is a batch script to zip files in folder or add /d to zip folders.
REM This script is using 7z to zip files, installation is required - "[][1]"
REM Remember to point 'do' to 7z installed path 7z.exe

SET input1=D:\Backup\SampleFolder
SET input2=D:\Backup\SampleFolder2

SET output1=C:\ZipBackups\SampleFolder
SET output2=C:\ZipBackups\SampleFolder2

CD /d %input1%
for %%X in (*) do "C:\Program Files\7-Zip\7z.exe" a "%output1%\" "%%X"
FORFILES /P "%input1%" /M *.* /D -8 /C "cmd /c del @file"

CD /d %input2%
for %%X in (*) do "C:\Program Files\7-Zip\7z.exe" a "%output2%\" "%%X"
FORFILES /P "%input2%" /M *.* /D -8 /C "cmd /c del @file"
share|improve this answer
set hour=%time:~0,2%
if "%hour:~0,1%" == " " set hour=0%hour:~1,1%
echo hour=%hour%
set min=%time:~3,2%
if "%min:~0,1%" == " " set min=0%min:~1,1%
echo min=%min%
set secs=%time:~6,2%
if "%secs:~0,1%" == " " set secs=0%secs:~1,1%
echo secs=%secs%

set year=%date:~-4%
echo year=%year%
set month=%date:~3,2%
if "%month:~0,1%" == " " set month=0%month:~1,1%
echo month=%month%
set day=%date:~0,2%
if "%day:~0,1%" == " " set day=0%day:~1,1%
echo day=%day%

set datetimef=%day%_%month%_%year%___%hour%_%min%_%secs%

echo datetimef=%datetimef%

path %path%;"C:\Program Files\7-Zip"
share|improve this answer
While this may answer the question, it would be a better answer if you could provide some explanation why it does so. – DavidPostill Nov 30 '14 at 7:41

You must log in to answer this question.

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