strange_things_happen
strange_things_happen

Reputation: 17

7-Zip Command-Line Help (Batch File)

I need to run 7-Zip from a batch file and perform a few tasks, I was wondering if it was possible. Here is my situation:

I have a folder "X:/Archived Backups/" that contains archives and sub-directories with archives.

Some of these archives also contain further archives.

I need to recursively scan the directory and sub-directories and 7-Zip to extract each archive to a folder by the same name (archive name).

I also need it to extract archives within archives within archives etc.

Finally, I need it to delete the archives when extracted (this includes the archives within archives) and only leave the extracted folders.

Is this possible? If so is it possible from the command line? How would I do it?

Many Thanks :)

Upvotes: 0

Views: 1996

Answers (2)

foxidrive
foxidrive

Reputation: 41234

Test this to see if it does what you need - it should extract them to x:\extracted\path\filename folders.

It doesn't delete the archives because you have to test this first.

Check the path to 7z.exe first.

@echo off
set "location=x:\extracted"
md "%location%" 2>nul
for /r "X:\Archived Backups" %%a in (*.7z) do (
   md "%location%\%%~pna"
      pushd "%location%\%%~pna" && ("c:\program files\7-zip\7z.exe" x "%%a" & popd)
)
pause

Upvotes: 1

kiran
kiran

Reputation: 525

You can use this post and this as starting points.

For iteration and testing directory:

FOR %%i IN (%VAR%) DO IF EXIST %%~si\NUL ECHO It's a directory

For files, check file extension and extract using 7-zip command :

Upvotes: 0

Related Questions