Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VBScript:  File Count of Folder and Subfolders

Posted on 2006-10-27
3
Medium Priority
?
7,986 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Introduction to Processes

618 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