IPB

Welcome Guest ( Log In | Register )

Batch m3u playlist creation for all folders, with the playlist named like the folder
zambaretzu
post Jul 3 2006, 19:54
Post #1





Group: Members
Posts: 22
Joined: 30-April 05
Member No.: 21806



I've been trying to find an easy way to do this, but I can't seem to find exactly what I need. I just want a simple way to:
  • go through all my folders recursively
  • for each folder with mp3s and oggs, making an m3u for each
  • have the m3u in the actual folder, not the root folder
  • name the m3u just like its containing folder.

Any help is appreciated.
Go to the top of the page
+Quote Post
 
Start new topic
Replies
masterofimages
post Jul 3 2006, 22:05
Post #2





Group: Members
Posts: 15
Joined: 10-May 02
Member No.: 2014



QUOTE (zambaretzu @ Jul 3 2006, 19:54) *
I've been trying to find an easy way to do this, but I can't seem to find exactly what I need. I just want a simple way to:
  • go through all my folders recursively
  • for each folder with mp3s and oggs, making an m3u for each
  • have the m3u in the actual folder, not the root folder
  • name the m3u just like its containing folder.
Any help is appreciated.


This script should sort you out:

CODE
Const ForReading = 1, ForWriting = 2, ForAppending = 8

delete = false
set args = WScript.Arguments
if args.Count > 0 then
    if LCase(args(0)) = "-d" then
        delete = true
    end if
end if

set fso = createobject("scripting.filesystemobject")
wscript.echo WriteM3u(fso.GetAbsolutePathName("."), delete) & " files written"

function WriteM3u(path, delete)
    dim count
    set fso = createobject("scripting.filesystemobject")
    set fdr = fso.GetFolder(path)
    if fdr.SubFolders.Count = 0 then
        m3u = path & "\" & fdr.name & ".m3u"
        if fso.FileExists(m3u) then
            if delete then
                wscript.echo "... deleting existing file"
                fso.DeleteFile m3u
            else
                wscript.echo "... renaming existing file"
                fso.MoveFile m3u, m3u & ".old"
            end if
        end if
        wscript.echo "... writing """ & fdr.name & ".m3u"""
        set m3ufile = fso.OpenTextFile(m3u, ForWriting, True)
        for each f in fdr.Files
            if right(f.Name, 3) = "mp3" or right(f.Name, 3) = "ogg" then
               m3ufile.WriteLine(f.Name)
            end if
        next
        m3ufile.Close
        count = 1
    else
        count = 0
        for each subfolder in fdr.subfolders
            wscript.echo "Searching """ & subfolder.path & """"
            count = count + WriteM3u(subfolder.path, delete)
        next
    end if
    
    WriteM3u = count
end function


Just save it to "WriteM3u.vbs" and stick it in the root directory of your mp3 and ogg files. To run, type:

CODE
cscript WriteM3u.vbs


By default it will rename any existing m3u files it finds. If you would rather delete them, just add "-d" to the end of the command-line, i.e.

CODE
cscript WriteM3u.vbs -d


-Paul
Go to the top of the page
+Quote Post
Julien
post Jul 4 2006, 01:14
Post #3





Group: Members
Posts: 53
Joined: 26-July 05
Member No.: 23534



Thank you Paul, this is a nice and useful script
Go to the top of the page
+Quote Post
masterofimages
post Jul 4 2006, 21:08
Post #4





Group: Members
Posts: 15
Joined: 10-May 02
Member No.: 2014



QUOTE (Julien @ Jul 4 2006, 01:14) *
Thank you Paul, this is a nice and useful script


Glad you found it useful. Enjoy biggrin.gif
Go to the top of the page
+Quote Post

Posts in this topic


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 29th August 2014 - 12:17