QUESTION :
I am trying to find a way to get a listing of all files, without hidden directories. I have tried several variations of something like this:
dir /b /s /a:-h z: >toc-z.txt
but this only skips over hidden files. I need a listing which excludes all hidden folders, including files and sub-folders of these hidden folders.
Is there any way I can skip parsing and listing of hidden folders?
ANSWER :
It’s a bit hackish, but you could probably use the xcopy
command with the /l
and /s
(or perhaps the /e
) options. The key is the /l
option which tells it to display a list of files that are to be copied rather than making any copies. By default, xcopy
does not copy hidden or system files so they will be ignored.
It’s a long command, but it works, and it is fairly fast 🙂
Here it is as a long one liner for the command line
>toc-z.txt ((for %F in ("z:*") do @echo %F)&for /f "delims=" %D in ('dir /s /ad-h-l /b z:*^|sort') do @for %F in ("%D*") do @echo %F)
Here it is as a batch file
@echo off
>toc-z.txt (
for %%F in ("z:*") do @echo %%F
for /f "delims=" %%D in (
'dir /s /ad-h-l /b z:*^|sort'
) do for %%F in ("%%D*") do echo %%F
)