Solved

Renaming files in a directory

Posted on 2015-01-12
6
192 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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 53

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

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…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
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…

786 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