FOR command cannot see hidden files
You could use forfiles
instead of for
.
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
for %i in (*) do echo "%i"
you'd use
forfiles /c "cmd /c echo @file"
or simply
forfiles
since "cmd /c echo @file"
is the default value for the command switch.
Here is one (ugly, unpleasant, non-ideal) work-around for files:
for /f "tokens=* delims=" %i in ('dir /b/a-d *') do echo "%i"
And a version for folders (analogous to for /d…
):
for /f "tokens=* delims=" %i in ('dir /b/ad *') do echo "%i"
And a version for both (no for
analog, so this is something of a benefit):
for /f "tokens=* delims=" %i in ('dir /b/a *') do echo "%i"
Recursive version for files (for… /r
):
for /f "tokens=* delims=" %i in ('dir /b/s/a-d *') do echo "%i"
And folders (for /r /d…
):
for /f "tokens=* delims=" %i in ('dir /b/s/ad *') do echo "%i"
And both
for /f "tokens=* delims=" %i in ('dir /b/s/a *') do echo "%i"
This works more or less, but definitely has its issues (especially for large sets of files or folders). Hopefully there is a better solution or Microsoft could fix/improve this in a patch.