By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Minor "For" issue...

While I would not call this a major problem because it has a very simple work around, I would say that it is something that does not work as one would expect. Specifically, the command "For /R %Root %F in (*.Example) Do (Echo %F) >&>ErrorFile.txt" does not work if "%Root" contains the drive letter of a non-existent drive ("Q:\", for example), and in this case it starts and recurses from the current directory on the current drive with the error file ("ErrorFile.txt") remaining empty. Again, there is a not all that inconvenient but possibly rather inefficient work around; specifically replacing the above by "For /R %Root %F in (*.example) Do (If EXIST %Root Echo %F)" does work. Similarly, if "%Root" contains the name of a non-existent directory on an existing drive, the same thing happens, again starting the recursion from the current directory on the current drive. I will note that if the error output is not redirected to a file the error message(s) are displayed, so maybe the real problem has something to do with redirecting standard error to a file in this situation. But in any case I tend to think that the command should not execute at all rather than starting the recursion from the current drive and directory.
From: mathewsdw
Summary of OP:

| for /r DR %x in (*) do ...

| If the path DR does not exist, either because it references a directory on a drive not ready, or because the specified directory does | not exist on the drive (though the drive is ready), FOR reports the error, and proceeds to execute in the current directory.

Problem verified using TCC 12.11.73 on WinXP home SP3 (32b).

Similar threads