Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / operating-systems / Windows

Batch Rename Multiple Files

4.00/5 (2 votes)
12 Sep 2013CPOL1 min read 18.1K  
How to rename various files from the shell

Introduction

I've needed from time to time to rename multiple files, last time it happened when I had to go from underscore (_) to dash (-) in all the files of the web page of my company (this helps in SEO tasks).

Using ren was not enough in that case and plenty of files were involved...  So I started an Internet search to find out how to perform that task.

Background

Almost no background apart of course to know how to open a command line window and power shell.

Using the Code

I'll do a small sample which is what worked for me, so in this power shell script you will see how to replace _ to - in all the files inside a folder.

You will have to open the power shell command line environment (search for powershell in the start menu and launch it).

Navigate to the folder you have all the files that need to be renamed (you know CD.. etc...).

Then execute that command:

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

This will do it and will replace that _ for - in all the file names.

There are other ways to do it like downloading the third party app Bulk-Rename-Utility (which is free, portable and will help you in all your rename needs).

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)