Sorry for the triple post, but this is sort of interesting and could be useful. You can avoid the step of writing to a text file by using the output of the dir /b command inside of the for command. The ‘usebackq’ option tells it to parse the output of the command as if it were a file. But note that you have to use back quotes (the ones over the tab key).
for /f “usebackq tokens=*” %i in (dir /b) do echo %i
Yeah, you can, but why? The FOR command has direct access to the list of files, so there’s no need to use a DIR command at all. The following does the exact same thing:
for %i in (*.*) do echo %i
Yes, but you can redirect stderr as well if you add a 2> option.
Using . doesn’t let you specify attribute types such as limiting it to just files for example. Not to mention that the extended for command is infinitely more powerful.
Yeah, it does. It limits it to files automatically unless you specify otherwise.
Using extended for is nice when you need it, but not when you don’t. Your example does not. It’s silly to use the more powerful form of a command just because you can, and not because you need to.
I even thought of an obvious example where using your method would be more advantageous–when you need it to occur in a certain order, as DIR has sort commands. That’s about all I can come up with, though.