Search code examples
7zip

7zip batch to compress all folders then delete original folder


I have a batch file which uses 7zip to zip all folders.

for /d %%X in (*) do "c:\Program Files\7-Zip\7z.exe" a "%%X.zip" "%%X\"

How can I delete the original folders now?

It would also be great if I could specify the size of the zip file like in the settings 'solid block style'


Solution

  • for /d %%X in (*) do "c:\Program Files\7-Zip\7z.exe" a "%%X.zip" "%%X\"
    for /d %%X in (*) do RMDIR "%%X" /S /Q
    

    This will do what you ask. A backup is not created, so make sure that you have copied your files safely before running this command. This silently removes the folder and subfolders after zipping them.