cmd - Compress separately files within subfolders -


hi , answers,

firstly, tried find answer problem did not find anything.

i have tree of folders , sub-folders , want use 7zip compress files within folders separately.

i have got piece of code website, want places compressed files on main folder:

    set extension=.*     /r %%a in (*%extension%) "%sevenzip%" -mx "%%~na.zip" "%%a" 

i wonder if can zip file of every file , have in sub-folder containing source file. or doing process above , place every zip file inside appropriate sub-folder.

i tried double 'for /d' unable it:

    cd /d %~dp0      rem 7z.exe path      set sevenzip=      if "%sevenzip%"=="" if exist "%programfiles(x86)%\7-zip\7z.exe" set       sevenzip=%programfiles(x86)%\7-zip\7z.exe       if "%sevenzip%"=="" if exist "%programfiles%\7-zip\7z.exe" set       sevenzip=%programfiles%\7-zip\7z.exe       if "%sevenzip%"=="" echo 7-zip not found&pause&exit      /d %%o in (*) (          /r %%i in ("%%o\*") (             "%sevenzip%" -mx "%%~na.zip" "%%a"              ::        rd /s /q "%%i"  **because not want delete now.          )     ) 

again, thank you.

alex.

if have complex folder structure better use plain list dir:

  dir /a:-d /s /b /o 

just use output in for:

for /f %%f in ('dir /a:-d /s /b /o') (   echo %%f <-- %%f full path file, ) 

btw, 7zip has useful option -sdel remove source file when archive has been created successfully.


Comments