Computing.Net > Forums > Programming > DOS 'For' Command

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

DOS 'For' Command

Reply to Message Icon

Name: sbkent2000
Date: October 23, 2009 at 09:18:47 Pacific
OS: Microsoft Windows XP Professional
CPU/Ram: 1.83 GHz / 2046 MB
Product: Dell / Precision m90
Subcategory: Batch
Comment:

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?



Sponsored Link
Ads by Google

Response Number 1
Name: tvc
Date: October 23, 2009 at 09:21:13 Pacific
Reply:

Because the resulting file is conform to the same initial requirement (*.vbs) ... shortcut that some way or another, and he will do it correct


0

Response Number 2
Name: sbkent2000
Date: October 23, 2009 at 09:57:30 Pacific
Reply:

Thank you for your reply. I'm not sure I understand. The 3 original files are:

file1.csv
file2.csv
file3.csv

The result is:

NewNameNewNamefile1.csv
NewNamefile2.csv
NewNamefile3.csv


0

Response Number 3
Name: Razor2.3
Date: October 23, 2009 at 14:28:18 Pacific
Reply:

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"


1

Response Number 4
Name: sbkent2000
Date: October 23, 2009 at 16:45:22 Pacific
Reply:

Worked perfectly! thanks for the assistance!


0

Response Number 5
Name: Mechanix2Go
Date: October 24, 2009 at 01:46:47 Pacific
Reply:

If it was DOS, which it isn't:

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


=====================================
Helping others achieve escape felicity

M2


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon





Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: DOS 'For' Command

DOS - FOR Command www.computing.net/answers/programming/dos-for-command/14596.html

c prog (Borland) for dos dir command www.computing.net/answers/programming/c-prog-borland-for-dos-dir-command/844.html

DOS for loop www.computing.net/answers/programming/dos-for-loop/17251.html