How do I search for non-hidden files in hidden subfolders using Windows Command Line

1

2

Looking through Google and super user stack exchange showed me how to search a folder and it's subfolder for hidden files

dir /A:H /S testHiddenFile*.txt

or hidden folders:

dir /A:HD /S testFolder

But how do I search through all sub folders (hidden or non-hidden) for all files with a particular extension. For example I want to find the location of *.log files under C:\Users\SomeUser\ but these files could be under hidden folders.

Ash

Posted 2017-08-30T07:55:49.197

Reputation: 111

Answers

2

Use attrib /s /d *.* command. See more: https://ss64.com/nt/attrib.html

Biswapriyo

Posted 2017-08-30T07:55:49.197

Reputation: 6 640

3

Taken and adapted from this answer, it will recurse through all folders whether or not they are Hidden and find files whether or they are hidden:

REM Recursive scan through all folders with or without Hidden attribute for any files
for /f "tokens=* delims=" %i in ('dir /b/s/a-d *') do echo "%i"

Adapted for your taste for finding all *.log files:

REM Recursive scan through all folders with or without Hidden attribute for .log files
for /f "tokens=* delims=" %i in ('dir /b/s/a-d *.log') do echo "%i"

If you want to save their directories to file myFiles.txt:

for /f "tokens=* delims=" %i in ('dir /b/s/a-d *.log') do echo "%i">>myFiles.txt

If you want to open all your files one at time:

for /f "tokens=* delims=" %%i in ('dir /b/s/a-d *.log') do (
    pause
    echo.
    echo Opening file "%%i"...
    notepad.exe "%%i"
)

El8dN8

Posted 2017-08-30T07:55:49.197

Reputation: 1 319

Thanks. Upvoted cause this worked as well, though it's longer than the answer in @Biswa's comment (attrib /s/d *.log). – Ash – 2017-08-31T04:55:48.233