Perhaps a dumb question: Why is necessary to identify in the list of elements produced by DIR command the ones that are files and the ones that are directories?
Code: Select all
for /F "delims=" %%a in ('dir /B') do (
if "%%a" is file (
process %%a as file
) else (
process %%a as directory
)
)
You may just process each type with the proper FOR command:
Code: Select all
for %%a in (*.*) do (
process file %%a
)
for /D %%a in (*) do (
process directory %%a
)
This code is simpler, clearer and run faster than the previous one. If both methods would be executed in all subdirectories of a large tree, the difference in run time between they may be notorious.
Of course, FOR /F ... in ('DIR...') may be
very useful in certain cases, but lately I have seen a series of examples that may be solved directly via plain FOR or FOR /D commands, but the OPs get in trouble when they wants to use a FOR /F instead...
Antonio