the evans center for sleep deprivation studies
« prev | current | next »
mar 29 2005 1:14am
mmmmm... easter.
mmmmm... easter.

cross-cutting files and folders.

I've spent a week of late nights -- that's all I have -- getting to know Cubase SX3 and easing into mixing yet another Sparge record. This one's pretty epic; thirteen musicians crammed into a NY studio for three days. We spend a lot of time on these records considering that nobody will ever hear them.

On that note, mixing real music on a PC sort of sucks, but at least I get to use my m4d h4x0r sk1llz to push around audio files. I thought it might be interesting to write about some of the tools and techniques that I use to massage filenames and folder contents.

If someone hands you folders full of inconsistently organized files, these batch techniques make it easy to recover your OCD-induced sanity. I use this stuff all the time, and not just for studio work -- for organizing mp3's, source code, photos, text files, whatever.

Most of this list is hopelessly unix-y (Cygwin, you are the wind beneath my wings), but not everything. If you have your own cool file-assaulting techniques -- Windows, Mac, vi, whatever -- please by all means post a comment.

0. Automate everything
This goes without saying, but don't do batch file manipulations by hand. It's boring as hell and you'll just mess something up anyway.

1. Total Commander
I'll start with the one graphical tool: Total Commander. TC is a two-pane Windows Explorer replacement. It's definitely for power users, the UI is kinda weird, but it rocks. (cost: $34, 30-day free trial)

Good goodness: Alt-F7 searches for files in lots of useful ways; "feed to list" puts search results back in one of the list panes; then you can move those search results, delete them, or best of all, Ctrl-M for the "multi-rename tool". The multi-rename tool is the shit. Search a directory tree for files named "*overhead*", then use multi-rename to replace "overhead" with "drums - OH" -- across all those directories, in one command.

(Another nice tweak: assign TC keyboard shortcuts to commands. I have Ctrl-F9 bound to "open a bash window in the current directory". Ctrl-F11 is "play selection in my mp3 player", and Ctrl-Shift-F11 is "enqueue selection in mp3 player".)

2. Name files so they sort
If you're numbering files, use 2- or 3-digit numbers (01, 02, etc) so they sort alphabetically. For dates, yyyy-mm-dd sorts. A leading underscore sorts before alphanumerics -- useful when you always want a certain file/folder to show up first in Explorer or Finder or ls.

3. Name files so they group when sorted
Bad:

backing vox
bass gtr
kick
guitar
lead vox
notes.txt
overheads
snare

Good:

_notes.txt
bass gtr
drums - kick
drums - overheads
drums - snare
guitar
vox - backing
vox - lead

Now for the tweaker unix stuff. I think Total Commander will do almost everything I do with scripts, but scripts is how I think.

4. Renamer scripts
More often than anything else, I need to be able to take a list of filenames, process the list somehow -- change extensions, add prefixes, whatever -- then hit "go" to rename them accordingly. I do this in emacs most of the time using gse-rename or wdired, but I used to use this script-generating script:

#!/bin/bash
echo "#!/bin/bash" > doit
echo "" >> doit

# Change the file globs as needed
for i in *.wav *.mp3 *.jpg ; do
   printf "mv %-60s \"%s\"\n" "\"$i\"" "$i" >> doit
done

This spits out another shell script with two columns of filenames. It's easy to edit the "after" column, then you run "./doit" to do the renaming. Only thing is, this doesn't do temporary renaming of everything to avoid problems if you're reusing filenames.

5. Rectangle functions
Emacs has lots of good "rectangle" functions; I assume other text editors do too. If you're going to use any of the renamers in #4, you need rectangles. Say you have these files:

kick.wav
snare.wav
OH.wav

Rectangles make it really easy to modify that list to:

drums_kick.wav
drums_snare.wav
drums_OH.wav

6. gse-number-rect
This is really another emacs/rectangle thing, but it's so life-changing that it gets its own bullet. gse-number rect prefixes a rectangle with ascending numbers:

01 - drums_kick.wav
02 - drums_snare.wav
03 - drums_OH.wav

I honestly use that every day. For non-emacs people, Total Commander's multi-rename tool has a similar feature.

7. One-liners
Once your kung-fu is happening, you can do a lot with bash one-liners. This weekend, I used this one to see if I had gotten all 1600 of my audio tracks named consistently:

ls -1 ?? | grep wav | sed 's/...//' | sort | uniq -c

Translation: list all the 2-character folders (01, 02, ...), find only the WAV files, get rid of the folder part of each listing, build a list of the unique filenames with counts for each one. If there were no filenames with low counts (hm, 7 files named "rack tom.wav" and 105 named "drums - tom 1.wav"), that meant that I won. Now we're making music.

That's all for now. Post comments if you have more techniques. I love this stuff.