Solved

Renaming files in a directory

Posted on 2015-01-12
6
191 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
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 17

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 11

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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 83

Accepted Solution

by:
oBdA earned 500 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 52

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

We have adopted the strategy to use Computers in Student Labs as the bulletin boards. The same target can be achieved by using a Login Notice feature in Group policy but it’s not as attractive as graphical wallpapers with message which grabs the att…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

912 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

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now