Create-VLCPlaylists.ps1
19 Sep 2025Description
Purpose
Creates VLC-compatible M3U playlists for MP3 files located in a specified directory and its subdirectories.
Detailed Description
The Create-VLCPlaylists function scans a given base directory and an optional subfolder for MP3 files. It creates M3U playlists for the MP3 files found directly in the specified directory or within its subdirectories.
Usage
Example 1
Create-VLCPlaylists -baseDir "\\deathstar.domain.leigh-services.com\Public\PodCasts\I'm Sorry I Haven't a Clue" -subFolder "Season81"
This command will create M3U playlists for MP3 files located in the “Season81” subfolder of the specified base directory.
Notes
Author: Your Name Date: Today’s Date
Script
<#
.SYNOPSIS
Creates VLC-compatible M3U playlists for MP3 files located in a specified directory and its subdirectories.
.DESCRIPTION
The Create-VLCPlaylists function scans a given base directory and an optional subfolder for MP3 files.
It creates M3U playlists for the MP3 files found directly in the specified directory or within its subdirectories.
.PARAMETER baseDir
The base directory containing the folders with MP3 files.
.PARAMETER subFolder
The subfolder within the base directory that contains the MP3 files or further subdirectories.
.EXAMPLE
Create-VLCPlaylists -baseDir "\\deathstar.domain.leigh-services.com\Public\PodCasts\I'm Sorry I Haven't a Clue" -subFolder "Season81"
This command will create M3U playlists for MP3 files located in the "Season81" subfolder of the specified base directory.
.NOTES
Author: Your Name
Date: Today's Date
#>
function Create-VLCPlaylists {
param (
[string]$baseDir,
[string]$subFolder
)
# Combine the base directory and subfolder to get the target directory
$targetDir = Join-Path -Path $baseDir -ChildPath $subFolder
Write-Output "Target directory: $targetDir"
if (-Not (Test-Path -Path $targetDir)) {
Write-Output "Error: Target directory '$targetDir' does not exist."
return
}
# Check if the target directory contains MP3 files directly
$mp3FilesInTargetDir = Get-ChildItem -Path $targetDir -Filter *.mp3 -ErrorAction SilentlyContinue
if ($mp3FilesInTargetDir.Count -gt 0) {
# Create playlist for MP3 files in the target directory
$playlistPath = Join-Path -Path $targetDir -ChildPath "$subFolder.m3u"
Write-Output "Creating playlist: $playlistPath"
Create-Playlist -mp3Files $mp3FilesInTargetDir -playlistPath $playlistPath
}
else {
# Get all directories within the target directory
$directories = Get-ChildItem -Path $targetDir -Directory
if ($directories.Count -eq 0) {
Write-Output "No directories found in '$targetDir'."
return
}
foreach ($directory in $directories) {
$season = $directory.Name
$playlistPath = Join-Path -Path $directory.FullName -ChildPath "$season.m3u"
Write-Output "Creating playlist: $playlistPath"
# Get all MP3 files in the current season directory
$mp3Files = Get-ChildItem -Path $directory.FullName -Filter *.mp3 | Sort-Object Name
if ($mp3Files.Count -eq 0) {
Write-Output "No MP3 files found in '$directory.FullName'. Skipping..."
continue
}
# Create the M3U playlist content
Create-Playlist -mp3Files $mp3Files -playlistPath $playlistPath
}
}
}
Download
Please feel free to copy parts of the script or if you would like to download the entire script, simply click the download button. You can download the complete repository in a zip file by clicking the Download link in the menu bar on the left hand side of the page.
Report Issues
You can report an issue or contribute to this site on GitHub. Simply click the button below and add any relevant notes. I will attempt to respond to all issues as soon as possible.