Microsoft > Microsoft DOS

How can I compress multiple depth subfolders?

(1/1)

Retro Jack:
Can anyone help me with a batch file to compress multiple depth subdirectories?

I would like to be able to turn

+---Pix
|   |   a.jpg
|   |   b.jpg
|   |   c.jpg
|   |   
|   \---Docs
|       |   a.doc
|       |   b.doc
|       |   c.doc
|       |   
|       \---Bills
|               a.xls
|               b.xls
|               c.xls
|               
\---Wishlist
    |   x.jpg
    |   y.jpg
    |   z.jpg
    |   
    \---Adverts
        |   x.doc
        |   y.doc
        |   z.doc
        |   
        \---Income
                x.xls
                y.xls
                z.xls

into

+---Pix
|   |   Pix.7z
|   |   
|   \---Docs
|       |   Docs.7z
|       |   
|       \---Bills
|               Bills.7z
|               
\---Wishlist
    |   Wishlist.7z
    |   
    \---Adverts
        |   Adverts.7z
        |   
        \---Income
                Income.7z


Notes:

* My archiver (7z.exe) is already set in my path environment variable, so the batch file doesn't need to know where it is.
* The contents of Piz.7z (for example)should only include the files in the Pix folder, not the contents of Docs or Bills.
Any help would be greatly appreciated.  :)

erobby:
If you are using 7 Zip "-r-" can be used to copy only current directory without subdirectories

Hackoo:
Hi  ;)
May be like this way :

--- Code: ---@echo off
Title 7z Compressing muti-subfolders
:: set the current directory to the batch file location
cd /d %~dp0
Call :Check_7Zip
@for /d /r %%D in (*) do (
PUSHD %%D
@for %%A in (*.*) do (
echo "%Zip%" a "%%D.7z" "%%A"
"%Zip%" a "%%D.7z" "%%A"
)
POPD
)
pause
Exit
::-----------------------------------------------------------------------------------------------------------------------------
:Check_7Zip
Reg Query "HKEY_CURRENT_USER\SOFTWARE\7-Zip" /v "Path">nul 2>&1
If [%errorlevel%] EQU [1] ( echo 7-Zip is not found !
) else (
@FOR /f "tokens=2*" %%i in ('Reg Query "HKEY_CURRENT_USER\SOFTWARE\7-Zip" /v "Path" 2^>nul') do (Set "Zip=%%j7z.exe")
)
Exit /B
::-----------------------------------------------------------------------------------------------------------------------------
--- End code ---

Navigation

[0] Message Index

Go to full version