I’m struggling with one of the most frustrating bugs I’ve ever come across.
Bug description:
The for
command of the command-interpreter cannot see hidden files.
Reproduction steps:
- Create a temporary directory
- Create a few files
- Assign a variety of attributes to the files (including hidden)
- Use a command like
for %i in (*) do echo "%i"
Expected results:
All files are processed in the for
loop either by default or though a switch.
Actual results:
- Files with any attribute other than hidden are processed; files flagged as hidden are skipped
- There is no switch to the
for
command to allow it to process hidden files
Implications:
There is no way to process all files from the command-prompt.
Question:
How the heck can hidden files be processed from the command-prompt or batch-files (at least in Windows if not DOS)?
Best Answer
You could use
forfiles
instead offor
.The syntax is quite different, but it has more functionalities (e.g., method to natively access the filename, the extension, the filesize and timestamp) and it processes all files by default.
For example, instead of
you'd use
or simply
since
"cmd /c echo @file"
is the default value for the command switch.