Want to delete specific range of characters from a file name

Welcome Forums General PowerShell Q&A Want to delete specific range of characters from a file name

Viewing 3 reply threads
  • Author
    Posts
    • #192892
      Participant
      Topics: 2
      Replies: 1
      Points: 16
      Rank: Member

      Hi everyone,

       

      I am trying to delete 20191110_20191210 from FTMR_20191110_2019121_20190112.

      Is there any method to do that?

       

      Thanks

       

    • #193000
      Participant
      Topics: 2
      Replies: 1693
      Points: 3,368
      Helping Hand
      Rank: Community Hero

      Is there any method to do that?

      Of course. You could use the substring method of the [STRING] type.

    • #193012
      Participant
      Topics: 1
      Replies: 4
      Points: 38
      Rank: Member

      Does this serve your purpose ?

      ($string.Replace("20191110_","")).Replace("20191210","")

      FTMR_2019121_20190112

    • #193078
      js
      Participant
      Topics: 27
      Replies: 739
      Points: 2,013
      Helping Hand
      Rank: Community Hero

      Assuming there's an extra 0 at the end of that part of the filename:

      dir FTMR_20191110_20191210_20190112 | rename-item -newname { $_.name -replace '20191110_20191210' } -whatif
      
Viewing 3 reply threads
  • You must be logged in to reply to this topic.