comtec100
asked on
Renaming a filename
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
Accepted answer: 0 points for comtec100's comment #a38716535
for the following reason:
script didn't quite work, but gave the framework. Thank you
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
Steve
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
~bp
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
~bp
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
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
ASKER
@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>chan
LOCALAPPDATA=C:\Users\Chan
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?