Click here to Skip to main content
15,867,771 members
Articles / Operating Systems / Windows
Tip/Trick

Batch Rename Multiple Files

Rate me:
Please Sign up or sign in to vote.
4.00/5 (2 votes)
11 Sep 2013CPOL1 min read 17.6K   2   5
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)


Written By
Chief Technology Officer robotecnik
Spain Spain
I'm from Catalonia (in Spain) and a specialist in CNC, PLC, robotics and automation in general.

From 1998 I've been developing software applications for the automation market.

I'm using different technologies in each case to get the proper result, fieldbus communications, special electronics, special laser sensors, artificial vision, robot arms, CNC applications, PLC's...

www.robotecnik.com[^] - robots, CNC and PLC programming

Comments and Discussions

 
Questioni would like to know Pin
Tibor Blazko5-Sep-15 20:56
Tibor Blazko5-Sep-15 20:56 
AnswerRe: i would like to know Pin
Joan M5-Sep-15 22:34
professionalJoan M5-Sep-15 22:34 
GeneralMy vote of 3 Pin
zahkoonkoo12-Sep-13 2:00
zahkoonkoo12-Sep-13 2:00 
GeneralRe: My vote of 3 Pin
Joan M12-Sep-13 3:36
professionalJoan M12-Sep-13 3:36 
GeneralRe: My vote of 3 Pin
zahkoonkoo12-Sep-13 4:00
zahkoonkoo12-Sep-13 4:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.