Squeezebox Server thumbnail creator

This script creates thumbnails for all cover images in the selected folder and subfolders. This speeds up the listings in Squeezebox. It uses Graphicsmagick for the actual converting.

I made this script because there was no easy way to do this in windows as there is no good find command like in *nix.

Save the script below as thumber.vbs and run from the command line:

cscript thumber.vbs "foldername"

Example:

cscript thumber.vbs "c:\My Music"

Dim fso, folder, folderName, coverFilenames, convertCommand, targetFilename

' Change this if you use other filenames
coverFilenames = "FOLDER.JPG,COVER.JPG"

' Change this if you want to use another target filename
targetFilename = "thumb.jpg"

' Change this if you want to use different parameters for converting the image
convertCommand = "gm convert -resize 50x50 ""#SOURCEFILENAME#"" ""#TARGETFILENAME#"""

If Wscript.Arguments.Count <> 1 Then
    WScript.Echo "Run from the command line: cscript thumber.vbs ""foldername"""
    Wscript.Quit
End If

folderName = Wscript.Arguments(0)

Set fso = CreateObject("Scripting.FileSystemObject")
Set oShell = WScript.CreateObject ("WScript.Shell")

If Not fso.FolderExists(folderName) Then
    WScript.Echo "The folder """ & folderName & """ does not exist"
    Wscript.Quit
End If

WScript.Echo "Scanning """ & folderName & """"

Set folder = fso.GetFolder(folderName)

processFolders(folder) 

Function processFolders(folder)
    Dim subfolder

  processFiles(folder)

    For Each subfolder in folder.SubFolders
        processFolders(subfolder)
    Next 
    Set subfolder = Nothing
End Function 

Function processFiles(folder) 
    Dim file, fileNames, cmd

    For Each file in folder.Files
      If InStr(coverFilenames, UCase(file.name)) > 0 Then
        cmd = convertCommand
        cmd = Replace(cmd,"#SOURCEFILENAME#",file.Path)
        cmd = Replace(cmd,"#TARGETFILENAME#",file.ParentFolder & "\" & targetFilename)
        Set cmdOutput = oShell.Exec(cmd)
        WScript.Echo cmdOutput.StdOut.ReadAll
      End If  
    Next 
    Set file = Nothing
End Function