making folders out of par2 file names

It seems that my decision to stay in Tacoma over Thanksgiving Break has allowed me to dork out more than usual.

Yesterday my benchies enlisted me to rescript the Secret Santa drawing website.
Last night I played DDR all night.
This morning I tinkered with Window's command line language so I could write batch scripts to make folders from par2 files.

Maybe the last one needs explanation. Believe it or not, my damn networking class has basically *forced* to me learn some linux bash commands. Since Randy is alway going on about the power of the command line over WYSIWYG interfaces, I decided to put an idea I had to the test.

In the past, I was always too lazy to learn the commands properly. Ironically, my laziness propelled me to navigate the commands so I could be even lazier. If that didn't make sense, you'll understand in just a second.

Although most of my underground rock collection is scene ripped, prior to this year I didn't really upload stuff so I would delete all my nfo/sfv/m3u files every time I got a release (stupid, stupid, stupid). Lately I've been using usenet to redownload these files and update my collection from previous years so it reflects my new interest in multiple genres. This results in a crapload of mp3s to be sorted into labeled folders. Luckily, par2 files are usually named with the scene release so I manually create new folders and rename them with the par2 file names.

If I have something like 20 different albums in one directory, that's a painstaking folder creation/renaming process that would take about 5 minutes even with all the keyboard shortcuts I use. Now with my new batch file, it takes me two clicks.

First, a visual example:


This is a temporary directory I setup with a bunch of PAR2 files I wanted to turn into empty folders.


Here's what the same directory looks like after I run "make_folders.bat". Pretty awesome, right? It even cleaned up the par2 files for me!

Ok, now that we've seen the magic, let's investigate the 3 lines of code that allowed me to do this so easily! Here's what's inside my batch file:

@echo off
FORFILES -m *.par2* -c "CMD /C md @FNAME"
del /q *.par2

The first line basically tells the command line not to show me each line of my batch file. Fair enough. I can toggled it on and off for debugging.

FORFILES is a command that reads from an executable file (forfiles.exe) that comes pre-packaged with Windows OS. If you have XP you'll need to download it from here and throw it in "WINDOWS/system32" because Windows is lamzers like that. FORFILES essentially allows me run the same command on a whole bunch of files. A batch within a batch, you say? Hmm.

Anyway, the first FORFILES call says look in the current directory for all files with ".par2" in their name and make a new folder named by the par2 file (without its extension). <--Yes this is what I use to spend minutes doing!

The second line says to look in the current directory and delete all the files with ".par2" in their name. "/q" mean do it quietly, don't prompt me before deleting. Unlike the the delete function in Windows GUI, the "del" command doesn't put stuff in your recycling bin, so be careful because your files are deleted forever.

Note: This batch file won't create new folders if I already have one of the same name in the current directory.

So that's the lesson for today...and probably the only one until I have lots of free time again (read: Christmas). If anything, you've learn how lazy can sometimes be a skill.

2 voiced:

Ebj said...

Hello. This bit of code was very useful to me, as I have a similar problem. I'd like to put forward a suggestion myself. If you replace both "par2" strings in your batch file with %1, you can then specify the extension of the files you want the folders created from. This has obviously the advantage of letting you adapt the batch file to multiple uses without having to edit it.
Technically speaking one should do a check to see that the %1 parameter isn't empty, lest undesirable effects happen when you use the file without parameters, but if you're careful you won't have to worry.

Cheers.

Ebj said...

Whoops. Forgot to mention: you specify the extension you want to pass to the batch file in the command line, like this:

make_folders par2
or
make_folders jpg

and so on.

 

Meet the Author

Hi, I am Julie.
Sometimes Jules Juke.
This is where I ramble, reflect, and refocus.