Link to home
Start Free TrialLog in
Avatar of debschultz
debschultzFlag for United States of America

asked on

Truncating a filename to create another filename using dos commands in a batch file

I have files that are automatically generated with the following format
910716_0.ATM  The number is alway unique.  I must rename this file using dos commands from a batch file.  The OS is Windows 2003 server.  So that I do have less of a chance to create a duplicate I need to change the filename to look as follows

rri10716.edi

Below I have been able to get the file to look like 10716 but I am having problems adding the rri in the beginning and the .edi extension

echo on & setlocal EnableDelayedExpansion
for %%J in (????????.ATM) do (set file=%%J:~1,5
   ren %%J !file:~1,5!)
ren file rri%%J
echo file > %file%

Avatar of oBdA
oBdA

Try this; it's currently in test mode and will only display the rename command it would normally run.
Remove the capitalized ECHO to run it for real:
echo on & setlocal EnableDelayedExpansion
for %%J in (????????.ATM) do (
  set file=%%~J
  ECHO ren "%%~J" "rri!file:~1,5!.edi"
)

Open in new window

Avatar of debschultz

ASKER

That did rename the file but the file did not have the content
What exactly do you mean with "the file did not have the content"? If the file didn't have a content before renaming, it obviously won't have content afterwards, either.
What exactly are you trying to achieve here, except renaming a file (which is the only function you required in your question)?
I  was playing around so let me say that when I tried what you gave me nothing happened.  The filename did not change for the .ATM
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you for your quick response