Removing the enDash [char]0x2013 from filenames

Welcome Forums General PowerShell Q&A Removing the enDash [char]0x2013 from filenames

Viewing 3 reply threads
  • Author
    Posts
    • #181218
      Participant
      Topics: 1
      Replies: 1
      Points: 21
      Rank: Member

      Hi all,

      I am struggling trying to remove a specific character from filenames. enDash, or [char]0x2013.

      Can someone help me with this ?

      Get-ChildItem -path $FileDir -Filter [char]0x2013 -Recurse | Rename-Item -NewName {$_.name -replace [char]0x2013, "_"}
    • #181344
      Senior Moderator
      Topics: 8
      Replies: 1155
      Points: 4,019
      Helping Hand
      Rank: Community Hero

      Isn't it working ? It works for me in PS 5.1 and later.

    • #181386
      js
      Participant
      Topics: 27
      Replies: 742
      Points: 2,030
      Helping Hand
      Rank: Community Hero

      Wouldn't you need wildcards?

      Get-ChildItem -Filter *$([char]0x2013)* | Rename-Item -NewName {$_.name -replace [char]0x2013, "_"} -whatif
      
    • #181428
      Participant
      Topics: 1
      Replies: 1
      Points: 21
      Rank: Member

      Thanks for the help!

      Got it working now 🙂

      Get-ChildItem -path $FileDir -Filter "*$([char]0x2013)*" -Recurse | Rename-Item -NewName {$_.name -replace [char]0x2013, "_"}

Viewing 3 reply threads
  • The topic ‘Removing the enDash [char]0x2013 from filenames’ is closed to new replies.