Removing the enDash [char]0x2013 from filenames

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

This topic contains 3 replies, has 3 voices, and was last updated by

 
Participant
1 week, 6 days ago.

  • 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: 1085
    Points: 3,651
    Helping Hand
    Rank: Community Hero

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

  • #181386
    js

    Participant
    Topics: 25
    Replies: 692
    Points: 1,721
    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, "_"}

You must be logged in to reply to this topic.