I can't get my Powershell script to work with a path which has square brackets.
Input path is "c:\temp\yeah [thats it]"
param (
[string]$folderPath = $env:folderPath
)
$folderPath = $folderPath + "\"
Add-Content -Path $folderPath"01-playlist.m3u" -Value "a file name.mp3"
I looked at '-literalpath' and 'Convert-path' but I can't see how to implement that to my code.
Simply use
-LiteralPath
instead of-Path
.Now the path is taken literally, so you cannot use wildcards as you would with
Path
.By the way, your optional parameter looks strange.. Unless you have set an environment variable for it, there is no such thing as
$env:folderPath
Also, to combine a path and a filename, there is a cmdlet called Join-Path. Using that is far better than using constructs like
$folderPath + "\"
where it is very easy to either forget backslashes or adding too many of them..Instead, I would write