DOS 'For' Command

Dell / Precision m90
October 23, 2009 at 09:18:47
Specs: Microsoft Windows XP Professional, 1.83 GHz / 2046 MB
I am attempting to 'rename' 3 .csv files in a directory using the following 'for' command in a batch file:

for %%i in (*.csv) do (rename "%%i" "NewName%%i")

The 3 files get renamed & then the first file in the directory gets renamed again to NewNameNewName.csv....

Why is this happening?

See More: DOS For Command

Report •

October 23, 2009 at 09:21:13
Because the resulting file is conform to the same initial requirement (*.vbs) ... shortcut that some way or another, and he will do it correct

Report •

October 23, 2009 at 09:57:30
Thank you for your reply. I'm not sure I understand. The 3 original files are:


The result is:


Report •

October 23, 2009 at 14:28:18
This comes up from time to time.
There appears to be a race condition when you combine FOR and REN. The workaround is to use FOR /F:
for /f "delims=" %%a in ('dir /b *.csv') do ren "%%a" "NewName%%a"

Report •

Related Solutions

October 23, 2009 at 16:45:22
Worked perfectly! thanks for the assistance!

Report •

October 24, 2009 at 01:46:47
If it was DOS, which it isn't:

ren *.csv N*.#
ren *.# *.csv

Helping others achieve escape felicity


Report •

Ask Question