Use 7z to backup each sub-directory to a separate file

1

My file structure is:

c:\csdata\folder1
c:\csdata\folder2
c:\csdata\folder3
etc

I'm trying to use 7z to backup all folders in csdata to their own archive to a temp folder (C:\butemp).

Here' what I have so far:

For /D %%i in (C:\csdata\*.*) DO 7za a "%%i.7z" "%%i"

The above works, but it creates the 7z file in the csdata folder, because %%i is equal to the full path.

Kevin Baker

Posted 2014-08-06T18:57:54.057

Reputation: 63

Answers

1

for gives you the ability to extract (and combine) various parts from the loop variable (taken from help for):

%~nI - expands %I to a file name only
%~xI - expands %I to a file extension only
(truncated)

The modifiers can be combined to get compound results:

%~dpI       - expands %I to a drive letter and path only
%~nxI       - expands %I to a file name and extension only
(truncated)

So you could use 7za a "C:\butemp\%%~nxi.7z" "%%i"

Run help for for more options

wmz

Posted 2014-08-06T18:57:54.057

Reputation: 6 132

Awesome.. thanks for the help and worked perfect! – Kevin Baker – 2014-08-06T19:53:32.823