Hi

I need to count the number of iles in a folder.

I have amended a script I found:

This is fine but it will not do subdirectories

Please can someone assist?
strComputer = "."

Set objWMIService = GetObject("winmgmts:" _

& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colFiles = objWMIService. _

ExecQuery("Select * from CIM_DataFile where Path = '\\currency\\'")

For Each objFile in colFiles

'Wscript.Echo objFile.Name

count1 = count1 + 1



'Wscript.Echo count1

Next

Wscript.Echo count1

Re: Counting Files In A Folder by McKirahan

McKirahan
Fri Mar 11 06:14:00 CST 2005

"qqqq" <dddh@ddd.clc> wrote in message
news:elvji6iJFHA.3376@TK2MSFTNGP14.phx.gbl...
> Hi
>
> I need to count the number of iles in a folder.
>
> I have amended a script I found:
>
> This is fine but it will not do subdirectories
>
> Please can someone assist?
> strComputer = "."
>
> Set objWMIService = GetObject("winmgmts:" _
>
> & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
>
> Set colFiles = objWMIService. _
>
> ExecQuery("Select * from CIM_DataFile where Path = '\\currency\\'")
>
> For Each objFile in colFiles
>
> 'Wscript.Echo objFile.Name
>
> count1 = count1 + 1
>
>
>
> 'Wscript.Echo count1
>
> Next
>
> Wscript.Echo count1
>
>

Not a WMI solution but will this help? Watch for word-wrap.

Option Explicit
'*
'* Declare Constants
'*
Const cVBS = "subfolds.vbs"
Const cFOL = "C:\temp"
'*
'* Declare Variables
'*
Dim intFIL
intFIL = 0
Dim intFOL
intFOL = 0
Dim strMSG
strMSG = cFOL & " contains:" & vbCrLf
'*
'* Declare Objects
'*
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
'*
'* Count subfolders and files
'*
Call Subfolders(objFSO.GetFolder(cFOL))
'*
'* Destroy Objects
'*
Set objFSO = Nothing
'*
'* Message
'*
strMSG = strMSG & vbCrLf & intFOL & " subfolders;"
strMSG = strMSG & vbCrLf & intFIL & " files."
MsgBox strMSG,vbInformation,cVBS

Sub SubFolders(Folder)
Dim objGFO
Set objGFO = objFSO.GetFolder(Folder)
intFOL = intFOL + 1
intFIL = intFIL + objGFO.Files.Count
Set objGFO = Nothing
'*
Dim Subfolder
For Each Subfolder in Folder.SubFolders
Call SubFolders(Subfolder)
Next
End Sub



Re: Counting Files In A Folder by Torgeir

Torgeir
Fri Mar 11 06:55:14 CST 2005

qqqq wrote:

> Hi
>
> I need to count the number of iles in a folder.
>
> I have amended a script I found:
>
> This is fine but it will not do subdirectories
>
> Please can someone assist?
Hi

You will need to use a recursive sub:

http://groups.google.co.uk/groups?selm=4005B38C.27CBDF3B%40hydro.com


--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx