How to automate sorting files into subdirectories?
January 31, 2008 10:49 AM   Subscribe

I have a large zipped MP3+G collection of about 30,000 songs split into several directories and subdirectories. I have them named by "Disc-Track - Artist - Title". for example... SC7501-01 - Presley, Elvis - An American Trilogy SC7501-02 - Presley, Elvis - Devil In Disguise SC7501-03 - Presley, Elvis - Burning Love Although I have some that are named by "Disc-Volume-Track - Artist - Title". CB5012-01-01 - Stray Cats, The - Rock This Town CB5012-01-02 - Looking Glass - Brandy etc... I'm hoping to automate the following: Within a directory (and all subdirectories) Create a subdirectory for files of the same disc (or disc-volume), and move the files for that disc into that subdirectory. Repeat until every file is moved into the proper subdirectory. I'm using Windows XP.
posted by fanboy65 to Computers & Internet (9 answers total) 1 user marked this as a favorite
Do you want to code this yourself? I've been working on a script to do something similar (see ).

I'm using javascript in an .hta application. ActivexObject(Scripting.FileSystemObject) will help you with the navigation of the existing directories, the creation of new ones and moving the files.

If you'd like to take a look at my (not 100% working) script, I'd be happy to share it with you.
posted by syzygy at 10:58 AM on January 31, 2008

If you're decent at scripting, you could just split off the Disc part of the filename and move the files to a folder with the "Disc" name. Create the folder if it doesnt exist.
posted by mphuie at 11:07 AM on January 31, 2008

Well, MP3Tag can do this somewhat easily. Given a track named "Disc - Volume - Track - Artist - Title", Mp3tag can use ID3 or APEv2 tags with the same information or the existing filenamer structure to re-organize a directory. Let it run an index the whole directory, CTRL+A to select all tracks, and use Convert> "Filename - Filename" to (for instance) rename "Disc 1 - Volume 1 - Track 1 - Elvis - Some Song.mp3" to "Disc 1\Volume 1\01 - Elvis- Some Song.mp3". I have more experience with using ID3 tags to create filenames and subdirectories but the documentation in the forums of the MP3tag site is excellent and the developer is responsive to questions.
posted by Inspector.Gadget at 11:08 AM on January 31, 2008

The Godfather also has an "organize" tab that's good for this kind of thing. It's a very powerful program, but not the easiest to use.
posted by whir at 1:05 PM on January 31, 2008

Tag & Rename is also jolly excellent.
posted by le morte de bea arthur at 1:20 PM on January 31, 2008

If you want to code this yourself, I suggest Perl (and Archive::Zip). But the fact that you asked this question suggests that you don't know Perl.

Y'all are suggesting MP3 organization programs. The problem is, his collection is zipped MP3+G. Good luck getting any of these programs to read it, much less handle it properly.
posted by mr.dan at 5:19 PM on January 31, 2008

For mass batches of file changes involving commonly patterned files, I always use RenameWand. It's simply the best, and it's free.

For your example:
java -jar RenameWand.jar "<album> - <track> - <artist> - <song>" "<artist>/<album>/<track> - <song>"
Would convert the first example you gave like this:

SC7501-01 - Presley, Elvis - An American Trilogy
/ Presley, Elvis
../ SC7501
../../ 01 - An American Trilogy

It'll even do a dry run before actually making the switch so you can see what you're going to get before doing a mass-commit. Which is nice if you forget a space or dash or something.
posted by Civil_Disobedient at 5:35 PM on January 31, 2008

Also, it can even convert case for you--so, let's say your files were labeled in all caps:


You could convert that to CamelCase, ALLCAPS, all lowercase, SOME uppercase, some lowercase, some CamelCase... it's all up to you. It's dead-simple to use.
posted by Civil_Disobedient at 5:37 PM on January 31, 2008

Thanks for everyone responding so quickly...any help is appreciated

Mp3tagging software isn't what I'm looking for. If all I had was just MP3s, I'm sure they would work wonderfully, but all my MP3s are zipped with the .cdg file (my hosting software plays zipped MP3+G). All my songs are named the way they are because that is what the Karaoke hosting software requires, so there is no need to tag them...and renaming the files is not an option for me.

I've been messing around with .bat files, but my knowledge is murky at best (I feel like I've forgotten most everything from the DOS days)...and I know next to nothing about scripting (although I have been going over some tutorials).

I have been playing with a few things I've found, but so far nothing I've found works 100%.

I did find this batch posted on this site.

@echo off
for /f "tokens=1* delims=-" %%a in ('dir /a:-d /b') do (
md "%%a" 2>nul
move "%%a-%%b" "%%a"

It seemed at first that it worked on my test files, but I noticed that it didn't move all the files into their subdirectories. The only common denominator I could find was that the songs that all the songs that didn't move had an apostrophe somewhere in the file name. I also couldn't figure out how to modify the batch to work with files in already existing subdirectories.

I did play with it a bit and managed to change it so it would work with "CB5012-01-01"

@echo off
for /f "tokens=1,2* delims=-" %%a in ('dir /a:-d /b') do (
md "%%a-%%b" 2>nul
move "%%a-%%b-%%c" "%%a-%%b"

...but then again, I'm still not moving all the files.

This is the only VBScript that I've messed with (again, I found this here at ask.metafilter).

Dim fso
Dim CurrentFolder
Dim Files
Dim NewFolderName
Dim TruncatedFileName
Dim MainFolder
Dim sh
Dim wx

Set fso = CreateObject("Scripting.FileSystemObject")
Set sh = CreateObject("Shell.Application")
Set wx = CreateObject("WScript.Shell")

On Error Resume Next
Set MainFolder = sh.BrowseForFolder(0, "Select Folder", 0, 17)
If Err then Err.Clear : WScript.Quit
On Error Goto 0

Set MainFolder = MainFolder.Self
If Not IsObject(MainFolder) Then WScript.Quit
If Not (LCase(Left(Trim(Typename(MainFolder)), 6))="folder") Then WScript.Quit

Result = wx.Popup("Do you want to process " & MainFolder.Path & "???",10, "Process Folder", 36)

If Result = 6 Then
ProcessFolder MainFolder
End If

Sub ProcessFolder(CurrentFolder)
Set Folders = CurrentFolder.SubFolders

' Folders first, then files
For Each Folder in Folders

Set Files = CurrentFolder.Files
For Each File in Files
If UCase(Right(File.Name,3)) <> "VBS" Then
TruncatedFileName = Left(File.Name, InstrRev(File.Name, ".") - 1)
NewFolderName = CurrentFolder.Path & "\" & TruncatedFilename

fso.CreateFolder NewFolderName
File.Move NewFolderName & "\"

End If
End Sub

I like the idea that I can run this script from my desktop, but I just can't get it to work for me (I just don't have the knowledge to edit it properly). Unfortunately I get the error "Object doesn't support this property or method: 'CurrentFolder.SubFolders'"

If any one would like to modify or even share your own batch or script, that would be great.
posted by fanboy65 at 8:09 PM on January 31, 2008

« Older Why should dogs sleep near their humans?   |   Voice-to-Midi for ableton Newer »
This thread is closed to new comments.