Thursday, 12 September 2013

For Loop Statement in DOS script is reading the input from file incorrectly - Loops failing

For Loop Statement in DOS script is reading the input from file
incorrectly - Loops failing

Hi I have this for loop reading lines from a file called "temp". It should
read each line and then proceed to create a directory for each name in the
file. However, It's reading the first line of the file twice before it
moves to the second line. So I get an error saying the folder already
exist.
the file "temp" contain for now 2 entry :
folder1
folder2
The code is simple
for /F "tokens=*" %%i in (temp) do (
set pstname=%%i
echo the folder name is set to %pstname%
mkdir C:\output\%pstname%
)
Ok - when I run this ..
it reads first line foldre1 from the "temp" file and creates the directory
c:\output\folder1 . So I expect the next time the variable pstname be set
to the second line in the "temp" file ( should be set to folder2)
but that is not what happens. The loop reads fodlerone twice and attempts
to create folder1 folder again. If I continue with the script it
eventually reads the second line from "temp" file ( folder two and creates
it. So the script almost works
Issue: What am I doing wrong? It reads the first line in the file "temp"
twice before it proceeds to the next line?
Is there a next command I have to use? what is wrong with my logic? Please
help
Can someone please help?

No comments:

Post a Comment