Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

echo off

cls

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

set filename="%date%.backup.zip"

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

3 Answers 3

up vote 1 down vote accepted

Use the syntax

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

so in your case, it'd be

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

Source: http://sevenzip.sourceforge.jp/chm/cmdline/switches/recurse.htm

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 - "[http://www.7-zip.org/a/7z938-x64.msi][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.zip" "%%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.zip" "%%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
1  
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.