Link to home
Start Free TrialLog in
Avatar of Klaatu59
Klaatu59

asked on

Rename file in DOS and change string

I am wanting to know if it is possible to rename a file in the following manner.
I am creating a file like 00000009.txt and want to rename the file to pyxbl00000009.txt with a batch file. The number will always be 8 characters I need to add pyxbl each time it is triggered.
Avatar of Michael Pfister
Michael Pfister
Flag of Germany image

Create a batch with:

for /f %%a in ('dir /b *.txt ^| findstr /I /X /R /C:^[0-9]*.txt') do ren %%a pyxbl%%a

It will filter all files beginning with a number (not neccessarily 8 digits) and rename them beginning with pyxbl. It will fail of course if a file with the new name already exists.

Hope it helps,

Michael
If you need to make sure to touch the 8-digit files only change  it like this:

for /f %%a in ('dir /b *.txt ^| findstr /I /X /R /C:^[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].txt') do ren %%a pyxbl%%a
If this is going to be done in true dos, won't the 8.3 filenames be a problem?
If this is going to be done in true dos, won't the 8.3 filenames be a problem?
Sorry for double post, internet glitch.
ASKER CERTIFIED SOLUTION
Avatar of Michael Pfister
Michael Pfister
Flag of Germany image

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