1

I have lots of old recorded video files of my kids which I wish to convert their names and get rid of the semicolons (;) and convert it to underscores (_). The file names looks like that:
Clip-2007-01-23 20;29;41-1.mkv

So I tried to use the following PS method:
Get-ChildItem -Filter "*;*" -Recurse | Rename-Item -NewName {$_.name -replace ';','_' }

But this is not working for me and after some analysis I figure out that the semicolons are not as they looks like but represented differently when looking into the file HEX representation... Each of the semicolons (;) signs in the file name is actually [CD] [BE] hex representation. see here 1 :

|43 6C 69 70 2D 32 30 30|37 2D 30 31 2D 32 33 30|   
|32 30 CD BE 32 39 CD BE|34 31 2D 31 2E 6D 6B 76|

So my question is how can I do this file rename?
Thank in advance

Erez Cohen
  • 11
  • 2
  • 2
    `$_.Name -replace '\p{Po}', '_'` should do. `Po` is the shorthand for the unicode category "Punctuation, other", which includes `U+037E`, the semicolon-looking character you've identified – Mathias R. Jessen Feb 10 '22 at 11:19
  • perfect! I run the following as you've suggested: Get-ChildItem -Recurse | Rename-Item -NewName {$_.name -replace '\p{Po}', '_' } And the file was renamed from: Clip-2007-01-23 20;29;41-1.mkv to be: Clip-2007-01-23 20;29;41-1_mkv (the dot was replaced also) So I run the following to fix it Get-ChildItem -Recurse | Rename-Item -NewName {$_.name -replace '_mkv', '.mkv' } Thanks a lot – Erez Cohen Feb 10 '22 at 11:54
  • Nice. You can exclude the dot from being matched: `-replace '[\p{Po}-[.]]', '_'` – Mathias R. Jessen Feb 10 '22 at 11:57
  • Or just do the replacement on the file's BaseName: `Rename-Item -NewName {'{0}{1}' -f ($_.BaseName -replace '\p{Po}', '_'), $_.Extension }` – Theo Feb 10 '22 at 12:24

0 Answers0