Search
Enter Keywords:
Home
VBScript to Make M3U Files from Directories PDF Print E-mail
User Rating: / 0
PoorBest 
Written by Michael Salsbury   
Tuesday, 17 January 2006
I've been organizing my MP3 collection, off and on, for several months now.  A while ago I managed to get them all organized by artist and album, weed out duplicates, get the ID3v2 tags in place, etc.  (Then, of course, my MP3 player went south on me, but that's another story.)  The first thing I noticed when I started listening to some of them was that I didn't have a playlist file (*.m3u) for some of them.  I didn't really care to make one of those by hand, so it was time to make a script!

That led me to develop the following script (for Windows systems with VBScript installed, which is most of them after Windows 98):

Const WINDOW_HANDLE = 0
Const OPTIONS = 0

Set fso = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder _
    (WINDOW_HANDLE, "Select a folder:", OPTIONS, "")

If objFolder Is Nothing Then
    Wscript.Quit
End If

Set objFolderItem = objFolder.Self
objPath = objFolderItem.Path

Set theFolder = fso.GetFolder(objPath)
Set filecoll = theFolder.Files
Set m3u = fso.CreateTextFile(objpath & "\" & theFolder.Name & ".m3u",vbTrue)

for each thisfile in filecoll
   theFile = thisFile.name
   If Instr(1,theFile,".mp3") > 0 THEN 
      m3u.WriteLine(theFile)
   End if
next

m3u.Close

The script works like this... Double-click it and you're presented with a Folder Selection Dialog box by Windows.  Use this dialog to navigate until you have selected a directory that contains a group of MP3s you want in the same playlist.  The script will parse the MP3 files out of that directory and build a playlist file for them.  The playlist file will be named to match the parent directory.

For example, imagine that I had a directory named "They Might Be Giants - No!" which contained the various tracks from the album "No!" by They Might Be Giants.  When I select that directory with the script, I'll end up with a file named "They Might Be Giants - No!.m3ui" which contains a playlist with all the MP3 files' names in it.  That M3U file will be compatible with Windows Media Player and (hopefully other media players, too).  Because I've designed the script to use just the filenames (instead of the whole path) it should work even if you move your MP3 directories around.  If you rename your files, it'll break.

Enjoy.  Use at your own risk.

Related Blogs:

Related Links:

Last Updated ( Monday, 23 January 2006 )
< Previous   Next >

Main Menu
Home
Blog
Photos
Links
Search
Site Index
Feedback
Administrator
Featured Links
BlogInspiration
SpamToons
Shawn Prince's Blog
Jack Ludwig's Blog
Mike Cramer's Site
Fark
Slashdot
Woot!
Cigar Envy
John Kricfalusi's Blog
CigarBlog 101
Cigars 101 Forum
Sponsored Links


View Site Stats