Solved

Renaming a filename

Posted on 2012-12-22
9
390 Views
Last Modified: 2012-12-27
I have a program that generates bunch of files automatically. i don't have control on the base program. I need to be able to change the names of the files. Here is a sample.

tblEmployee.cs -> Employeedto.cs
tblDept.cs -> Deptdto.cs

I need to remove 'tbl' from the prefix and add 'dto' as the suffix before the file extension.

can someone please provide me the code for this renaming in MS DOC batch file?


Thanks a bunch,
Chandra
0
Comment
Question by:comtec100
[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
  • 3
  • 2
  • 2
9 Comments
 
LVL 55

Accepted Solution

by:
Bill Prew earned 500 total points
ID: 38716455
Give this a try.

@echo off
Set local enabledelayedexpansion
Pushd c:\yourdir
For %%A in (tbl*.cs) do (
  Set Name=%%~nA
  Ren "%%~A" "!Name:~3!dto.cs"
)
Popd

Open in new window

~bp
0
 

Author Comment

by:comtec100
ID: 38716535
Script:
@echo off
Set local enabledelayedexpansion
Pushd c:\Users\Chandra\temp
  For %%A in (tbl*.cs) do (
  Set Name=%%~nA
  Ren "%%~A" "!Name:~3!dto.cs"
)
Popd


Result:
C:\Users\Chandra\temp>changename.bat
LOCALAPPDATA=C:\Users\Chandra\AppData\Local
A duplicate file name exists, or the file
cannot be found.
A duplicate file name exists, or the file
cannot be found.
A duplicate file name exists, or the file
cannot be found.
A duplicate file name exists, or the file
cannot be found.

Can you please help?
0
 

Author Comment

by:comtec100
ID: 38716962
I've requested that this question be closed as follows:

Accepted answer: 0 points for comtec100's comment #a38716535

for the following reason:

script didn't quite work, but gave the framework. Thank you
0
On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

 
LVL 43

Expert Comment

by:Steve Knight
ID: 38716683
The script would work as is IMO except there is a spurious space on the set local line.  Changed to just setlocal it should be fine.

Steve
0
 
LVL 55

Expert Comment

by:Bill Prew
ID: 38716956
Sorry for the extra space in setlocal, worked this question on a mobile device and it was nice enough to put in that space on its own, argh.

~bp
0
 
LVL 55

Expert Comment

by:Bill Prew
ID: 38716963
Given the posters final comment, shouldn't http:#a38716455 be accepted as the solution or at least a points scoring assist, in which case the poster should post their modified working version.

~bp
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 38717663
Agreed give Bill the points, was only a space added!

My mobile seems to auto-complete words really annoyingly and doesn't seem to allow turning it off in a browser text box, you hit a space after a word in a piece of code and it helpfully adds the last bit of text you had after that combination etc.  Must delve a bit for the "off" button on that I suppose!

Steve
0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
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.

726 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