Fugogugo
Fugogugo

Reputation: 4480

windows batch file to read all the super hidden file/directory

I wanna create a batch file that could do something to all folder in the current directory. but I found out that using this syntax

for /d %%i in (*) do echo %%i 

it cannot find the hidden file. so is there any additional syntax need to be added?

Upvotes: 1

Views: 1180

Answers (1)

Andriy M
Andriy M

Reputation: 77667

Not sure if anything could be done to fix the behaviour of FOR /D, but you could use a different approach. You could use the output of DIR in a FOR /F loop.

Now the DIR command accepts arguments, which allows you to achieve the necessary output. In particular, you can instruct DIR to only display the names of hidden directories (/ADH) and do so without other information, like date&time and summary (/B). Run DIR /? or HELP DIR at the command prompt for more information.

So, your loop might look like this:

FOR /F "delims=" %%D IN ('DIR /ADH /B') DO ECHO %%D

The delims option of the FOR /F loop instructs the loop to consume entire lines of the DIR output, as opposed to reading up to the first space, which is the default behaviour. You can learn more about it calling the help on FOR at the command prompt: FOR /? or HELP FOR.

Upvotes: 1

Related Questions