PlayList Maker (M3U)

Here's a little DOS Batch file that will output the contents of a folder (and subfolders) to a M3U Playlist.
I put mp3 ogg and mp4 as the defaults, but you can add some more (or take some out).

Create a batchfile (playlist.bat) and add these lines:

@for /f "delims=." %%A in (%0) do set playlist=%%A
@dir *.* /a-d /b/s |findstr "mp3 ogg mp4" > "%playlist%.m3u"

You'll notice that the output is a file of the same name as your bat file without the bat extension (playlist.m3u).

Remember, it recurses folders so you'll get alot of output if you put it on a root folder of your massive mp3 collection. To change it to non recursive (no subfolders) just take out the /s from the second line.


Anonymous said...

Thanks a lot, really useful and simple to do!
Sorry, what kind of language is used? C? I'd like to modify a little your code in order to replace the folder name.
Anyway, many thanks!

Blademonkey said...

it's actually DOS/Command Line.
Findstr is part of most Windows XP installs, i should have probably mentioned that.

Anonymous said...

Yes, you mentioned that... ;-)
Sorry if I bother you, but since I'm actually unable to modify that, may I ask you if there's a chance to modify your code in order to get the folder name instead of "playlist" name? do you think it is possible to do?
Anyway, again, thanks for your useful code! ;-)

Blademonkey said...

I think it's possible but i'd more details.
so do you mean if I have a c:\Music folder with the following subfolders:

You want a playlist that assumes the name of each folder?
That's possible but you have to consider that since this is recursive it will do the same for sub-subfolders and subsubsub folders. Unless that is what you want. Sorry, I'm am slow, but i am also optimistic in that i think it's possible, just need more details.

Anonymous said...

Hi again! First of all, thanks for your respond, I was afraid to excessively bother you with my request.
What I mean is the following.
e.g.: what I usually do now is to put your .bat file in a album folder containing .mp3 files and execute it in order to create a playlist which is obviously called "playlist.m3u".
I'm asking you if it's possible to modify your code in order to get "folder_name.m3u" instead of "playlist.m3u". No subfolders needed, for now.
e.g.: my last legal downloaded album from iT*nes is called "abc" and I save its mp3s in a folder called "abc". If I put your batch file in this folder I'll get a playlist called "playlist.m3u". Well, I'd like to have, if it's possible of course, a playlist called "abc.m3u". This could come useful while using a media player on a pc or cellphones which reads promptly album playlist.
I hope I explained my point pretty well. If not, please note me. Sorry for my English mistakes and thanks again for having answered so quickly.

Blademonkey said...

try this:
@dir *.* /a-d /b |findstr "mp3 ogg mp4" > "%cd%.m3u" && move %cd%.m3u %cd%

Anonymous said...

Ok, it works but partially. I mean: your code creates a playlist correctly named as the folder containing it, but it is not copied into its folder, but in the up-folder... Sorry, I'm not sure it's clear!
e.g.: Documents/abc contains mp3s;
start the batch; it creates abc.m3u in Documents; it doesn't copy it in Documents/abc.

Anonymous said...

Ok, it's simple: instead of typing "move /y "%cd%.m3u" %cd%"
I typed %cd..% and... it works!
Thanks! Many thanks!

Blademonkey said...

woot so what's the final code you're using. i'll add it to my post.

Anonymous said...

If I've understood well, here it is:
@for /f "delims=." %%A in (%0) do set playlist=%%A
@dir *.* /a-d /b |findstr "mp3 ogg mp4 avi" > "%cd%.m3u" && move %cd%.m3u %cd..%

Anonymous said...

This will be my last comment, I promise.
I tried this kind of code:

@dir *.mp3 /B /L /ON > "%cd%".m3u && move %cd%.m3u %cd..%

This works, too. As yours.
Tried in Win Vista.
Thanks for your patience. Bye!

Blademonkey said...

hmm interesting. %cd..% does not work in XP. they must have made changes in the xp cmd.

thanks for the update.

Donald Brown said...

Is there a way to randomize the playlist? The program works flawlessly, but I would like a way to randomize the playlist when it is generated.

Donald Brown

Jonathan Bowley said...

Thanks for this guide! I'm using this code, but it creates an empty m3u file size 0kb. What could be the issue?