Enhanc... erm, extract!
1 min read

Enhanc... erm, extract!

We've all been there, haven't we? We just downloaded the latest seaso... erm, Linux distro and it came with lots of folders which in turn contain lots of archives, one folder per episode. One way to do things is to just extract each episode... erm, distro, by hand, watch it, move to the next and so on.

Another way would be to write a Windows batch script to make 7-zip go through all the archives and extract their contents, which means you run it once and end up with all the files out.

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

Note that if you're running a 64bit OS but don't have the 64bit version of 7-zip installed you need to change "C:\Program Files\7-zip\7z.exe" x %%X into "C:\Program Files (x86)\7-zip\7z.exe" x %%X

Launch the bat, and all rar's/zips will be extracted into the folder they are contained in.

Now let's be helpful and dissect the script, shall we?

FOR /D /r %%F in ("*") DO (

This is a simple for loop to go through all folders in the current directory, and put the path into a variable %%F.

pushd %CD%

Put the current directory into memory.

cd %%F

Set the folder from variable %%F as the current directory.

FOR %%X in (*.rar *.zip) DO (

For all the archives (rar and zip) in the current folder, do:

"C:\Program Files\7-zip\7z.exe" x %%X

Run 7-zip on the files with the extract parameter (basically call the command line version of 7-zip telling it to extract the current archive)

popd

Return to the previous directory stored in memory.

That's it! Pretty simple and efficient, isn't it?