1 year ago

#229161

test-img

Jeff A

How to properly format a Copy-Item when filenames and file paths have apostrophes and brackets?

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',

windows

powershell

copy-item

0 Answers

Your Answer

Accepted video resources