Want to delete specific range of characters from a file name

Hi everyone,

 

I am trying to delete 20191110_20191210 from FTMR_20191110_2019121_20190112.

Is there any method to do that?

 

Thanks

 

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

Does this serve your purpose ?

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

FTMR_2019121_20190112

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