Batch File rename files with number

Novice February 5, 2009 at 15:09:30
Specs: Windows XP
I have some txt files that are named:
a-0.txt
a-1.txt
a-2.txt

and so on... (up to around 700 txt files)

I'm trying to rename them in the sequence:

a1000000.txt
a1000001.txt
a1000002.txt

The orignal files, and the renamed files are all in the same directory "_DOWNLOAD".

Can anyone help?

Thank You.


See More: Batch File rename files with number

Report •


#1
February 5, 2009 at 15:27:46
Are the first 2 chars always a- or do they need to be discovered?


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#2
February 5, 2009 at 16:04:00
Yes.
They are always a-x.txt
As the files get numbered, they will expand such as:
a-10.txt
a-11.txt
a-100.txt

I was hoping to Insert A1 as the first 2 characters. They are used to identify the source. The "a-" characters can be discarded.

Thank you for the quick response!


Report •

#3
February 5, 2009 at 16:47:31
As is, it previews what's to be done. After testing you activate it by removing the ECHO in front of ren.

=========================================
@echo off & setLocal EnableDelayedExpansion

for /f "tokens=* delims= " %%a in ('dir/b a-*.txt') do (
set S=%%~Na
set s=!S:~2,22!
call :pad
echo ren %%a 1!S!.txt
)

goto :eof

:pad to 6
if !S:~5^,1!'==' set S=0!S!& goto :pad
goto :eof


=====================================
If at first you don't succeed, you're about average.

M2


Report •

Related Solutions

#4
February 5, 2009 at 17:03:49
Your solution is exactly what I was looking for!
I did a slight change to bring in the A before the 1 on the renamed files. I don't know much about this site, but I can't express how impressed I am!

@echo off & setLocal EnableDelayedExpansion

for /f "tokens=* delims= " %%a in ('dir/b a-*.txt') do (
set S=%%~Na
set s=!S:~2,22!
call :pad
ren %%a A1!S!.txt
)

goto :eof

:pad to 6
if !S:~5^,1!'==' set S=0!S!& goto :pad
goto :eof

Thank You Mechanix2Go for helping out an old novice.


Report •

#5
February 5, 2009 at 17:07:49
oops, I forgot the A

LOL


=====================================
If at first you don't succeed, you're about average.

M2


Report •


Ask Question