0

I posted yesterday about a litany of MP3 files that are in a Plex playlist which I want to put on my local PC and upload to an MP3 player. While I was able to get some of the basics down, I encountered some issues going forward with all ~850 songs.

After figuring out that tracks with an & would throw an error, I enclosed everything in "xyz" double quotes.

After running the script:

Copy-Item -Path "\\192.168.1.14\Synology Media\Music\The Wombats\Greek Tragedy\01 Greek Tragedy.mp3", "\\192.168.1.14\Synology Media\Music\DJ El-Bravo\Dem Bow Mix Tape Vol. 2\The Way I Are (Chachi Remix).mp3", "\\192.168.1.14\Synology Media\Music\Whilk and Misky\The First Sip [Single]\Babe I'm Yours.mp3", "\\192.168.14\Synology Media\Music\Big Sean\One Man Can Change The World\One Man Can Change The World.mp3" -Destination C:\Users\Jeff\Desktop\Copy

I noticed that I was missing about 100 songs. I determined that it was a result of files that had square brackets, [ or ], as part of their file name or path. To rectify this, I had to enclose those files in single quotes and add a backtick, for example,

'\\192.168.1.14\Synology Media\Music\Whilk and Misky\The First Sip `[Single`]\Babe I'm Yours.mp3',

However, the issue then became cases like the above example where there is an apostrophe in the path or filename. The I'm apostrophe acts as though that ' is that closing '`' and not just part of the file name. And enclosing it in double quotes will not work.

Is there a proper way to format this kind of filename structure?

Here are a few extra examples of files with this issue.

'\\192.168.1.14\Synology Media\Music\Imagine Dragons\Continued Silence EP `[Single`]\It's Time.mp3'

"\\192.168.1.14\Synology Media\Music\Blink 182\Glorious\Adam's Song (Kasum Remix).mp3",

'\\192.168.1.14\Synology Media\Music\Victoria Bigelow\To Everyone I've Loved Before `[Single`]\To Everyone I've Loved Before.mp3',

'\\192.168.1.14\Synology Media\Music\The Pharcyde\Sold My Soul The Remix & Rarity Collection `[Disc 2`]\Runnin' (Bit Funk Remix).mp3',

Jeff A
  • 33
  • 5
  • So you want to type 850 song names manually? – stackprotector Feb 26 '22 at 19:13
  • The easy solution would be to not have literals. Does `Copy-Item -Recurse '\\192.168.1.14\Synology Media\Music\'` not do it? If you must have some "curated" list of names that can't be done automatically, stick them in a text file and read that with `Get-Content` (`Copy-Item -Path (Get-Content myfiles.txt)`). – Jeroen Mostert Feb 26 '22 at 19:21
  • I don't want to copy the entire music directory, just the specific files. The MP3 player can only hold 32GB, and my '\\192.168.1.14\Synology Media\Music\' library is over 100GB. I have an M3U file with all of them listed and accounted for. So if I instead write the files to a txt, how will I want to call that with Get-Content? Is it like `Get-Content (Copy-Item -Path "\\192.168.1.14\Synology Media\Music\Files.txt") -Destination C:\Users\Jeff\Desktop\Copy`? – Jeff A Feb 26 '22 at 19:50
  • 1
    To robustly process _literal_ file paths (rather than _wildcard_ expressions), use the `-LiteralPath` parameter, not `-Path` - see the linked duplicate. Use double-quoting (`"..."`), so that paths with single quotes (apostrophes, `'`) are handled correctly; if paths happen to contain literal `$` characters, escape them as `\`$` – mklement0 Feb 26 '22 at 20:05
  • Could you use `[regex]::escape()` – shadow2020 Feb 27 '22 at 02:41

0 Answers0