windows files per folder

I have a root folder containing a number of sub folders. I want a way to specify the root folder, and it produce a summary of how many files are in each sub folder. Is this possible? There may be a few levels of sub directory in each sub folder.
LVL 3
pma111Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Nadav SolomonCommented:
Enjoy
function getSubDirs($dir)
{
    "$dir contains $((getNumberOfFiles($dir)).count) files"
    dir $dir -Directory | %{
        getSubDirs($_.FullName)
    }
}

function getNumberOfFiles($dir)
{
    dir $dir -File |measure |select count
}

getSubDirs C:\Windows

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pma111Author Commented:
hi nadav what scripting language is the above written in? is it a vbs?
0
Nadav SolomonCommented:
powershell, you used a tag of powershell.
0
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

pma111Author Commented:
thanks
0
Nadav SolomonCommented:
if you want vbscript (just for the fun here it is)
Set fso = WScript.CreateObject("Scripting.Filesystemobject")

getDirs("c:\windows")

sub getDirs(path)
	Set folder = fso.GetFolder(path)
	On Error Resume Next 
	WScript.Echo path & " contains " & folder.Files.Count & " files."
	If Err.Number <> 0 Then
		WScript.Echo path & " " & Err.Description
		Err.Clear
	End If 
	For Each fld In folder.SubFolders
		getDirs(fld.ShortPath)	
	Next 
End sub 

Open in new window


You are most welcome.
0
Nadav SolomonCommented:
Thanks for the feedback
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows 7

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.