Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I found a script on here that would use 7zip and extract all the files in all the sub-folders of a specific folder and put them in their own folder using the script below.

What I need is add to it or maybe use another script if i have to and specify where i want those files to go instead of putting them in their own folder within the folder. I don't know how to do this and hope someone would be able to help.

Thanks for the help

 @echo on

FOR /D /r %%F in ("*") DO ( 
      pushd %CD% 
     cd %%F 
        FOR %%X in (*.rar *.zip *.tar) DO ( 
                "C:\Program Files\7-zip\7z.exe" x -o"%%~nX" "%%X"

share|improve this question
Thank you for the script, and welcome to server fault! Because this is a Q&A site, it's helpful if you write your question as a question, and then post your own answer to it (seeing as how you have one). –  Falcon Momot Oct 14 '13 at 7:23
How long does it normally take for a reply? I would have thought someone here would know what code to use for moving the file. Thanks –  Onyxius Oct 17 '13 at 15:49
Oh, I guess you hadn't answered your question at all. Enjoy. People will answer these whenever they have time and feel like doing that, so it can take a very long or short time. –  Falcon Momot Oct 17 '13 at 20:16

1 Answer 1

You can specify the destination folder with the x subcommand, but you are already doing this with


You need to replace the %%~nX with an expression that indicates where you want the extracted files to go. The option takes a directory name.

share|improve this answer
So say replace that with c:\temp? or whatever folder i want it to end up in? –  Onyxius Oct 17 '13 at 23:06
Yup. Put like -o"C:\temp". –  Falcon Momot Oct 18 '13 at 2:59
Awesome, thank you Falcon, worked perfectly :D –  Onyxius Oct 18 '13 at 22:13
Great; glad it helped you. Feel free to accept my answer; we both get reputation for this, and it helps keep the Q&A from being auto-deleted. –  Falcon Momot Oct 19 '13 at 0:03

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.