Solved

Renaming files in a directory

Posted on 2015-01-12
6
190 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 16

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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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 51

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Can I legally transfer my OEM version of Windows to another PC?  (AKA - Can I put a new systemboard in my OEM PC?) Few of us are both IT and legal experts but we all have our own views of Microsoft's licensing rules and how they apply.  There are…
Sometimes people don't understand why download speed shows differently for Windows than Linux.Specially, this article covers and shows the solution for throughput difference for Windows than a Linux machine. For this, I arranged a test scenario.I…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

758 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

18 Experts available now in Live!

Get 1:1 Help Now