Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Renaming files in a directory

Posted on 2015-01-12
6
Medium Priority
?
196 Views
Last Modified: 2015-01-12
Hi,

There are 150 sql files in a directory all with the heading
Test_Prog_1.sql
Test_Prog_2.sql
.
.
.
Test_Prog_150.sql

Is there a way I can rename all the "Test" to "Final" easily?
Resulting in
Final_Prog_1.sql
Final_Prog_2.sql
.
.
.
Final_Prog_150.sql

PS: The OS is windowsXP
0
Comment
Question by:csharp_learner
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40544099
You can use a program such as Bulk Rename Utility - www.bulkrenameutility.co.uk
You can batch remove Test and batch add Final to the filenames; and the programme is free.
0
 
LVL 18

Expert Comment

by:Emmanuel Adebayo
ID: 40544101
Open a notepad

Enter the following

rename Test_Prog_1.sql Final_Prog_1.sql
rename Test_Prog_2.sql Final_Prog_2.sql
rename Test_Prog_3.sql Final_Prog_3.sql
rename Test_Prog_4.sql Final_Prog_4.sql
rename Test_Prog_5.sql Final_Prog_5.sql
rename Test_Prog_6.sql Final_Prog_6.sql
rename Test_Prog_7.sql Final_Prog_7.sql
.
.
.
.
.
.
.
.
.
rename Test_Prog_150.sql Final_Prog_150.sql

Save this as test_rename.cmd or whatever name that suite you.

Run test_rename.cmd  from the command prompt

Note:Please ensure that you have a backup of the directory you are chaning.
0
 
LVL 12

Expert Comment

by:Tej Pratap Shukla ~Dexter
ID: 40544124
hi..

For the same you can use the Bulk Rename Utility. That is available free of cost. you can download it from the internet and can perform the required renaming

bulk-rename.png
bublk.png
And you have done. Hope this will work for you
0
Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
LVL 85

Accepted Solution

by:
oBdA earned 2000 total points
ID: 40544191
Plain batch; the script is currently in test mode and will only display the "ren" commands it would normally run, so that you can test it. Remove the uppercase ECHO in line 8 to run it for real:
@echo off
setlocal
set Folder=C:\Temp
set OldPrefix=Test
set NewPrefix=Final
for /f "tokens=1* delims=_" %%a in ('dir /b "%Folder%\%OldPrefix%_*.sql"') do (
	echo Processing '%%a_%%b' ...
	ECHO ren "%Folder%\%%a_%%b" "%NewPrefix%_%%~b"
)

Open in new window

0
 
LVL 57

Expert Comment

by:Bill Prew
ID: 40544226
Here is a smal BAT script you can use.  Save as a BAT file, adjust the BaseDir to be the folder where the files are, and test it.  Right now it will only echo the rename commands to the screen, not rename the files, so you can validate it will rename properly.  If it looks good, then remove the ECHO before the REN command and run for real.

@echo off
setlocal EnableDelayedExpansion

set BaseDir=c:\folder

pushd %BaseDir%

for %%A in ("test_*.*") do (
  set CurrentName=%%~nxA
  set NewName=Final_!CurrentName:~5!
  ECHO ren "!CurrentName!" "!NewName!"
)

popd
pause

Open in new window

~bp
0
 

Author Closing Comment

by:csharp_learner
ID: 40545978
Worked perfectly.
Thanks.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question