Wildcard behavior in renaming multiple files

PumpkinPants 1 Reputation point
2021-08-01T03:01:56.167+00:00

I have been trying to rename files that are listed below

E01-pHi10PAAC--62144D67--1-.txt
E02-pHi10PAAC--62144D67--1-.txt
E03-pHi10PAAC--62144D67--1-.txt
...etc

using command line
D:\PATH> dir | Rename-Item -NewName {$_ -replace "pHi*",""}

So my intention is to delete whatever after "pHi" in the file names

But the problem is that when I type the command and run it, it only delete "pHi"
I just wonder if I am doing anything wrong or if there is any case wildcard is not accepted

Thank you ahead!

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,873 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Viorel 114.7K Reputation points
    2021-08-01T05:42:37.387+00:00

    If you need names like E01-pHi.txt, then try one of solutions:

    dir | Rename-Item -NewName {$_ -replace "pHi[^.]+","pHi"}

    0 comments No comments