debschultz
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%
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%
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)?
What exactly are you trying to achieve here, except renaming a file (which is the only function you required in your question)?
ASKER
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you for your quick response
Remove the capitalized ECHO to run it for real:
Open in new window