vb script to count content in folder

Hello Experts:

I am looking for vb script to count the number of files present in the folders. I am looking for following output

I will be running this script on the network folders...


Open in new window

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.

NVITEnd-user supportCommented:
If a .bat files is ok with you, try this.

- Save code to desired name. The example uses dirsizes.bat

@echo off
set t1=%temp%\t1.txt

set SrcDir=%1
if not exist "%SrcDir%\*" goto :error

pushd "%SrcDir%"
for /d %%a in (*) do (
  dir /s "%%a" | find "File(s)" >"%t1%"
  for /f %%A in (%t1%) do set TSize=%%A
  echo %%a,!TSize!
goto :eof

echo "%SrcDir%" missing
goto :eof

Open in new window

- To run it:
dirsizes.bat z:\network\foldername

Open in new window

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
CalmSoulAuthor Commented:
thanks can I run it like this?

dirsizes.bat \\network\foldername

Open in new window

NVITEnd-user supportCommented:
I tested it on local drive c:. Still, it should work. Try it.

If it doesn't, just map a drive letter to that path before running it. e.g. if letter x: is not currently used:
net use x: \\network\foldername

Open in new window

Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

NVITEnd-user supportCommented:
I've confirmed that it does work using a format like \\network\foldername
Bill PrewIT / Software Engineering ConsultantCommented:
Can you be more specific?  Are you only looking at the folders in the single base folder, or did you want all folders at all levels?

Also, did you want the file count just at the first level of a folder, or for all files underneath that folder, including nested subfolders?

Bill PrewIT / Software Engineering ConsultantCommented:
Here is a basic approach using VBS since you asked, currently it just goes down one level, but can easily be modified as needed.

Save as a VBS, then run passing the base folder, like:

cscript filecount.vbs "c:\temp"

' Get folder name to process from command line
If (WScript.Arguments.Count > 0) Then
  sDirName = WScript.Arguments(0)
  WScript.Echo "No folder name specified."
End If

' Make sure folder exists
Set oFSO = WScript.CreateObject("Scripting.FileSystemObject")
If Not oFSO.FolderExists(sDirName) Then
  WScript.Echo "Folder does not exist."
End If

' Access this folder
Set oFolder = oFSO.GetFolder(sDirName)

' Look at each subfolder, display it's file count
For Each oSubFolder In oFolder.SubFolders
   Wscript.Echo oSubFolder.Files.Count & "," & oSubFolder.Name

Open in new window

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
VB Script

From novice to tech pro — start learning today.