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.
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?
comtec100
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
Steve Knight
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.
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
Bill Prew
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
Steve Knight
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!
@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?