The escaping issue is between the square brackets, the pound sign is okay.
if I change the directory and file name
$(Get-Item -LiteralPath 'C:\A\[Sun-King] Master - Photo Set #1\[Sun-King] Master - Photo Set #1_001.jpg').CreationTime=$(Get-Date "2/16/2017 4:32:02 PM")
to
$(Get-Item -LiteralPath 'C:\A\[Sun King] Master - Photo Set #1\[Sun King] Master - Photo Set #1_001.jpg').CreationTime=$(Get-Date "2/16/2017 4:32:02 PM")
and then run the ps1 file with the command
pwsh -f filelist.ps1
it works fine but I have far too many directories (including some that are archived) to replace each and every occurrence of the dash between the square brackets.
I’m not sure why the -LiteralPath or even using single qoutes is attempting to parse the path as a wildcard, but maybe you can try a different method. It looks like you are just getting JPG’s from a dir, so can see if this works:
If it does not, you will need to escape the characters, like the square brackets. The square brackets are most likely the issue as they are regex meta characters. So, you may need to make the path like so:
Strange. I tried powershell core in win7 sp1 64-bit and had no errors. I guess you can try using ‘?’ instead of brackets and -path instead of -literalpath. You don’t really need either ‘$’.
Tried both ideas and still same issue. I’m at a loss. I’m going to maybe see if I can do this via a cygwin session as a workaround for directories with a dash between square brackets.
And it is the dash that is mucking things up. If I copy the directory and contents and rename said directory and contents with an underscore, space, etc it works flawlessly. Unfortunately renaming every single file/directory currently on disk and the ones archived is not feasible.
Yes I tried the ? in place of the - and no change (and yes I’m sure it is a dash and not an em dash). Just tried it with an em dash (alt 0151) in place of the - and it worked fine…it is just the dash that breaks it.
Unfortunately, like I said, renaming is not an option as it breaks with the archived files. I’ll just have to keep digging and seeing what I can come up with.