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...

folder1,3
folder2,400
....

Open in new window

LVL 5
CalmSoulAsked:
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.

NVITCommented:
If a .bat files is ok with you, try this.

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

@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
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!
  )
)
popd
goto :eof

:Error
echo "%SrcDir%" missing
goto :eof

Open in new window


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

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

dirsizes.bat \\network\foldername

Open in new window

0
NVITCommented:
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

0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

NVITCommented:
I've confirmed that it does work using a format like \\network\foldername
0
Bill PrewCommented:
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?

~bp
0
Bill PrewCommented:
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)
Else
  WScript.Echo "No folder name specified."
  WScript.Quit
End If

' Make sure folder exists
Set oFSO = WScript.CreateObject("Scripting.FileSystemObject")
If Not oFSO.FolderExists(sDirName) Then
  WScript.Echo "Folder does not exist."
  WScript.Quit
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
Next

Open in new window

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

From novice to tech pro — start learning today.