Barney said:
How can I, from within a script, determine the total
number of files contained within a folder and all of its
subdirectories? Ideally, this should include hidden,
system and read-only files.
There are many, many ways to achieve this. Below is but one example -
[From the command prompt]
for /f %c in ('dir "C:\My Documents" /s/a-d/b ^| find /c /v "UnLiKeLy To
ExIsT"') do set TOTFILES=%c
[Within a script]
for /f %%c in ('dir "C:\My Documents" /s/a-d/b ^| find /c /v "UnLiKeLy
To ExIsT"') do set TOTFILES=%%c
In both cases, the TOTFILES variable will now contain the total number
of entries (excluding directories themselves but inclusive of their file
content) within, in my case, "C:\My Documents". If you would also like
the directories themselves counted, simply remove the "-d" from the
arguments "/s/a-d/b" resulting in "/s/a/b".
HTH
Dean