[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

VBScript:  File Count of Folder and Subfolders

Posted on 2006-10-27
3
Medium Priority
?
7,990 Views
Last Modified: 2012-06-21
Greetings, Experts.  I'm looking for VBScript code that will allow me to accomplish the following goals:

1)  perform a count of the total number of files within a server folder, including the total number of files in any subfolders that may exist.
2)  send an e-mail to select users, persuming that the server has Outlook installed.  For example:  "The total number of files for <path> is ###."

Is this possible?  Does this exist?

Thanks, Experts!

Todd
0
Comment
Question by:todjklki
  • 2
3 Comments
 
LVL 35

Accepted Solution

by:
mvidas earned 500 total points
ID: 17821455
Hi Todd,

There isn't an existing function to do exactly this, but you can always write it :)

Change the foldername, smtpserver, and destination addresses as needed.  If you don't have CDO installed on the machine, this could be changed to use the outlook object.

 Dim FSO, vPath, FileCnt
 Set FSO = CreateObject("scripting.filesystemobject")
 vPath = "C:\folder name\"
 FileCnt = 0
 ReturnFileCountUsingFSO vPath, FileCnt
 If FileCnt > 0 Then
  SendMailCDO "The total number of files in '" & vPath & "' is " & FileCnt, "mysmtpserver"
 End If
 Set FSO = Nothing
 Set vPath = Nothing
 Set FileCnt = Nothing

Function ReturnFileCountUsingFSO(vPath, FileCnt)
 Dim f, fld
 On Error Resume Next 'in case no permission for folder
 Set fld = FSO.GetFolder(vPath)
 FileCnt = FileCnt + fld.Files.Count
 For Each f In fld.SubFolders
  ReturnFileCountUsingFSO f.path, FileCnt
 Next
 On Error GoTo 0
 Set f = Nothing
 Set fld = Nothing
End Function

Function SendMailCDO(strBody, SmtpServer)
 Dim objCDO
 Set objCDO = Nothing
 On Error Resume Next
 Set objCDO = CreateObject("CDO.Message")
 On Error GoTo 0
 If objCDO Is Nothing Then 'cdo must not be installed on the machine
  SendMailCDO = False
  Exit Function
 End If
 With objCDO
  .Subject = "File Count"
  .From = "FileCount@domain.com" 'address does not have to exist
  .To = "joe.smith@domain.com;john.johnson@domain.com"
  .TextBody = strBody
  With .Configuration.Fields
   .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
   .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SmtpServer
   .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
   .Update
  End With
  .Send
 End With
 Set objCDO = Nothing
 SendMailCDO = True
End Function

Matt
0
 

Author Comment

by:todjklki
ID: 17821495
TOO SWEET!  Awesome work, Matt!

Todd
0
 
LVL 35

Expert Comment

by:mvidas
ID: 17821529
Glad to help!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn different types of Android Layout and some basics of an Android App.
The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Progress

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question