Rename multiple iles in folder using Batch

July 9, 2009 at 16:09:42
Specs: Windows XP
Hi,

I have to rename all the files in a particular
folder using Batch programming. I am able to
rename it only one file and
the other files gets ignored. Could some one
help me with the code ?
FOR %%l in (D:\Test\*.*) do (SET
FNAME=%%~nxl) & call:rename
:rename
ren %FNAME% test.%FNAME:~4%.txt
This does rename (remove existing prefix and
add a new prefix) for the first file in the folder
but how to continue the same process for the
rest of the files ?

Could someone please let me know ...

Thanks for your help ...


See More: Rename multiple iles in folder using Batch

Report •


#1
July 9, 2009 at 16:19:37
for /f "tokens=* delims= " %%a in ('dir/b/a-d d:\test') do (


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

M2


Report •

#2
July 9, 2009 at 17:42:49
Thanks a lot ! It works now ... But the loop ran one more time
than expected.

I had 2 files in my directory and the it ran for 3 times and the
3rd time it said "The system cannot find the file specified"

could you pls tell me: ('dir/b/a-d d:\test') - what it does ?

Thanks again ...


Report •

#3
July 9, 2009 at 17:47:43
Run it at the prompt and see for yourself.


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

M2


Report •

Related Solutions

#4
July 9, 2009 at 18:06:45
Yup, I can find that.

Thanks for your help ...


Report •

#5
July 10, 2009 at 14:04:58
Hi,

Need your help, My For Loop runs one more time than
expected. I could not find the problem. This is the command

for /f "tokens=* delims= " %%a in ('dir/b/a-d d:\test') do (SET
FNAME=%%~nxa) & call:rename

:rename
ren %FNAME% test.%FNAME:~15%.txt

The loop runs 3 times when I have 2 files in the directory.
Could someone pls let me know how to fix this ?

Thanks for your help ...


Report •

#6
July 10, 2009 at 23:24:13
for /f "tokens=* delims= " %%a in ('dir/b/a-d d:\test') do (
SET FNAME=%%~nxa
call :renamer
)

goto :eof

:renamer
ren %FNAME% test.%FNAME:~15%.txt

goto :eof


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

M2


Report •

#7
July 24, 2009 at 11:34:41
Thanks a lot ... It works perfect !

Report •

#8
July 24, 2009 at 11:41:12
There is a change in rename requirement and I need your
help:

The file name that needs to be renamed has a .txt suffix and
the renamed file names should not have the .txt suffix
Could someone please let me know how to accomplish this in
the below script ? It would be really helpful ...

for /f "tokens=* delims= " %%a in ('dir/b/a-d d:\test') do (
SET FNAME=%%~nxa
call :renamer
)
goto :eof
:renamer
ren %FNAME% test.%FNAME:~15%
goto :eof


Report •

#9
July 24, 2009 at 11:47:13

For example: solution_123.txt needs to be renamed to
test_123

The code below renames the prefix as I need but the .txt
suffix is not removed. Could someone pls suggest ?


There is a change in rename requirement and I need your
help:
The file name that needs to be renamed has a .txt suffix and
the renamed file names should not have the .txt suffix
Could someone please let me know how to accomplish this in
the below script ? It would be really helpful ...
for /f "tokens=* delims= " %%a in ('dir/b/a-d d:\test') do (
SET FNAME=%%~nxa
call :renamer
)
goto :eof
:renamer
ren %FNAME% test_%FNAME:~15%
goto :eof


Report •

#10
July 24, 2009 at 12:05:27
Looking for a reply ...

Report •

#11
July 26, 2009 at 02:45:40
@echo off

for /f "tokens=* delims= " %%a in ('dir/b/a-d d:\test') do (
SET FNAME=%%~na
call :renamer
)
goto :eof
:renamer
ren %FNAME% test_%FNAME:~15%
goto :eof


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

M2


Report •


Ask Question