Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mass file renaming - PowerShell [closed]

Tags:

powershell

I have many files in a folder with this format

constant_blah_blah_blah.png

How can I replace the underscores with spaces and also remove the constant_ from them using PowerShell?

Thanks in advance.

like image 223
Tsarl Avatar asked Dec 29 '25 15:12

Tsarl


1 Answers

# gather all files that match the criteria
Get-ChildItem constant_* |
   ForEach-Object {
      # remove the "constant_" from the beginning and replace _ by space.
      Rename-Item $_ ($_.Name -replace '^constant_' -replace '_', ' ')
   }

Or shorter:

ls constant_* | %{rni $_ ($_.Name -replace '^constant_' -replace '_', ' ')}
like image 143
Joey Avatar answered Jan 01 '26 11:01

Joey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!