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.

I need to set up an archiving task on Windows 7 using Windows command line and WinRAR (or some other similar program). I want to create a script that does this, but I have no prior experience.

I want to be able to:

  • recreate folders substructure down to a specified level

  • have the contents of each sub-folder at the last level be archived in one archive bearing the name of that sub-folder

  • password protect the archive

  • split the archive into chunks of a specified size

  • have the ability to include only files with the A(rchive) attribute

  • clear the A(rchive) attribute after archiving

  • have the possibility to exclude certain files and folders, by specifying them in a text file.

Any help is much appreciated.

I am also ready to learn new things, so pointing me to some tutorials that would help me accomplish this task is also very much appreciated.

Edit:

Consider the following example: assume I want to archive the contents of a folder called DOCS and recreate its structure down to Level 2 ('DOCS' is considered to be Level 0). Assume that the structure of sub-folders, down to the second level is the following:

DOCS\L1-A\L2-A\

DOCS\L1-A\L2-B\

DOCS\L1-A\L2-C\

DOCS\L1-B\L2-A\

DOCS\L1-B\L2-B\

DOCS\L1-B\L2-C\

I want to obtain the following structured back-up (on a different partition or drive):

DOCS\L1-A\L2-A\L2-A.rar

DOCS\L1-A\L2-B\L2-B.rar

DOCS\L1-A\L2-C\L2-C.rar

DOCS\L1-B\L2-A\L2-A.rar

DOCS\L1-B\L2-B\L2-B.rar

DOCS\L1-B\L2-C\L2-C.rar

share|improve this question
1  
Have you looked at the WinRAR command-line options and identified those that might help you? Can you also explain your second requirement in detail, preferably with a small example? –  Karan May 25 '13 at 14:25
    
@Karan: I edited the op and gave a minimal example. I looked over WinRAR command-line options, but I can't recreate the folder structured as mentioned (all the other aspects can be achieved within WinRAR, but I don't know how to go through the folder structure automatically). –  digital-Ink May 25 '13 at 14:55
    
Hmm, what you want to do (separately archive the contents of each 2nd level dir) might be possible with a fairly complex batch script. Do you absolutely need this to be done via batch though? IMO something like this might be much easier to accomplish in PowerShell instead of breaking your head over a batch-based solution. –  Karan May 25 '13 at 15:07
    
@Karan: Any kind of solution is welcomed. –  digital-Ink May 25 '13 at 15:17
1  
I'm not a PS expert, but I edited the tags so hopefully those keeping a watch on the PS tag will be notified of this question and respond. –  Karan May 25 '13 at 15:27

1 Answer 1

This works for step 1 and 2; this creates a rar file named "Level2Name.rar" for each of the level 2 folders in a mirrored folder tree structure:

If you want to include the folder tree structure inside the rar file ("Docs/Lv1/Lv2/Files") just remove -ep from the winrar command.

setlocal
set savelocation=D:\Backups
set path=%path%;C:\Program Files\WinRAR
for /F "eol= usebackq delims=" %%A IN (`dir "DOCS" /A:D /B`) do call :FL1 "%%A"
goto :eof

:FL1
pushd DOCS\%1
set level1="%~nx1"
for /F "eol= usebackq delims=" %%A IN (`dir * /A:D /B`) do call :FL2 "%%A"
goto :eof

:FL2
set level2="%~nx1"
POPD
if not exist "%savelocation%\DOCS\%level1%\%level2%" mkdir "%savelocation%\DOCS\%level1%\%level2%"
winrar a -ibck -inul -ep "%savelocation%\DOCS\%level1%\%level2%\%level2%.rar" "DOCS\%level1%\%level2%"
goto :eof

endlocal 
share|improve this answer
    
+1 Haven't tested this myself, but looks good! –  Karan May 25 '13 at 17:11

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.