0

OneDrive is not syncing multiple files with an illegal character in their filename. The character is a black dot symbol.

Screenshot of an example as I can't copy/paste the dot into text!

enter image description here

Can someone please help me with removing this character in a quick manner?

I ran a PowerShell script that successfully removed ! & { } ~ # % " characters, but this dot has me stumped!

I believe these files originated from a Mac.

Thanks in advance.

1
$Pattern = "[^a-zA-Z0-9\s]"
$mystring -replace $Pattern

for more information see here: https://blogs.technet.microsoft.com/heyscriptingguy/2014/12/06/weekend-scripter-remove-non-alphabetic-characters-from-string/

regex cheatsheet: http://www.rexegg.com/regex-quickstart.html

  • Thanks for your help. I ran the following command but no luck, no files were renamed. I believe I am close. Can you please help? Get-ChildItem | Rename-Item -NewName { $_.Name -replace '^[a-zA-Z0-9\s]+$','' } – Ash Jun 14 '18 at 3:50
  • Sorry i did a typo in the regex. It should be: -replace '[^a-zA-Z0-9\s]+$]' note the ^ character. I've updated my post above. Alternatively you can also just use the regex '[\W]' to get the opposite of word characters. You also don't need the second blank parameter in the -replace statement. I've also update this in the answer above. – Jay Jun 14 '18 at 5:16
  • I noticed another typo in my regex... I've simplified it and tested it working. Code I used was: Get-ChildItem -Path "c:\test" | Rename-Item -Path {$_.FullName} -NewName { $_.Name -replace '[^a-zA-Z0-9\s]' } Your code should look like: Get-ChildItem | Rename-Item -NewName { $_.Name -replace '[^a-zA-Z0-9\s]' } or Get-ChildItem | Rename-Item -NewName { $_.Name -replace '[\W]' } . Up to you which to use. \s is whitespace – Jay Jun 14 '18 at 5:31
0

We can remove the Unicode characters using PowerShell. Refer here

Example $String -replace '[^\u0030-\u0039\u0041-\u005A\u0061-\u007A]+', ''

You can look up for the Unicode of the character online.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.