Solved

Renaming files in a directory

Posted on 2015-01-12
6
195 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 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 85

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 56

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
AutoHotkey is an excellent, free, open source programming/scripting language for Windows. It started out as a keyboard/mouse macros product, but has expanded into a robust language. This article provides an introduction to it, with links to addition…
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…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

635 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