Reputation: 17
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
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