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.

Cfinley
  • 1,435

1 Answers1

2

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
  • 7,358