Replace strings from filenames with Windows Powershell

Asked

Viewed 3,307 times

1

How to replace strings from batch file names using Windows PowerShell?

Ex: Replace the " " character with the "_" of all files in a folder.

1 answer

1


To do this you can use the following command:

Dir -R | Rename-Item -NewName { $_.name -replace " ","_" }

which in this case will fetch and rename files recursively ( -R). It is also possible to filter files that will be renamed by extension using a parameter *.cpp

Dir -R *.cpp| Rename-Item -NewName { $_.name -replace " ","_" }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.