Wildcard behavior in renaming multiple files

PumpkinPants 1 Reputation point

I have been trying to rename files that are listed below


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,852 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Viorel 112.9K Reputation points

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

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

    0 comments No comments