-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathEdit-Playlist.ps1
47 lines (36 loc) · 1.21 KB
/
Edit-Playlist.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<#
.SYNOPSIS
Replace the path of all items in a playlist file to the current user's MyMusic path.
.PARAMETER Path
The path of the playlist files. Default is current directory
.PARAMETER Replace
The string to replace in each item path.
.PARAMETER Type
The file type of the playlists. Default is m3u
.DESCRIPTION
I use this because I maintain Dopamine playlists (.m3u files) on my primary device
and copy them to other devices which sometimes have different paths for MyMusic.
This quickly let's me update all .m3u files to the current machine's config.
#>
# CmdletBinding adds -Verbose functionality, SupportsShouldProcess adds -WhatIf
[CmdletBinding(SupportsShouldProcess = $true)]
param(
[parameter(Position = 0, Mandatory = $true)]
[string] $Replace,
[string] $Path = $pwd,
[string] $Type = 'm3u'
)
$slash = [IO.Path]::DirectorySeparatorChar
if (!($Replace.EndsWith($slash)))
{
$Replace = $Replace + $slash
}
$music = [Environment]::GetFolderPath('MyMusic') + $slash
Write-Host "... Music is located here: $music"
Write-Host
Get-Item "*.$Type" | % `
{
$fullName = $_.FullName
Write-Host "... updating $fullName"
(Get-Content $fullName | % { $_ -replace $Replace, $music }) | Set-Content $fullName
}