Hey Everyone,
I am working on a current script that calculates the total number of files ONLY then e-mails them to me. I am needing to change the script and add the total number of folders. Example would be this ...
"C:\GS"
"C:\GS\1"
"C:\GS\2"
.... etc
and this e-mail would just tell me 3 folders and X number of files. Below is the VBScript I'm working with to at least get the total number of files.
Dim FSO, vPath, FileCnt
Set FSO = CreateObject("scripting.filesystemobject")
vPath = "C:\gs\"
FileCnt = 0
ReturnFileCountUsingFSO vPath, FileCnt
If FileCnt > 0 Then
SendMailCDO "The total number of files in '" & vPath & "' is " & FileCnt, "MY E-MAIL SERVER"
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 = True
Exit Function
End If
With objCDO
.Subject = "File Count"
.From = "THEIR E-MAIL ADDRESS" 'address does not have to exist
.To = "MY E-MAIL ADDRESS"
.TextBody = strBody
With .Configuration.Fields
.Item(" = 2
.Item(" = SmtpServer
.Item(" = 25
.Update
End With
.Send
End With
Set objCDO = Nothing
SendMailCDO = True
End Function
So bottom line is I would like it to calculate the number of folders and files in the C:\GS folder and have it in the e-mail. Again currently all I see in the e-mail is "The Total Number of Files in C:\GS is XXX".
Any help would be honestly appreciated it!
I am working on a current script that calculates the total number of files ONLY then e-mails them to me. I am needing to change the script and add the total number of folders. Example would be this ...
"C:\GS"
"C:\GS\1"
"C:\GS\2"
.... etc
and this e-mail would just tell me 3 folders and X number of files. Below is the VBScript I'm working with to at least get the total number of files.
Dim FSO, vPath, FileCnt
Set FSO = CreateObject("scripting.filesystemobject")
vPath = "C:\gs\"
FileCnt = 0
ReturnFileCountUsingFSO vPath, FileCnt
If FileCnt > 0 Then
SendMailCDO "The total number of files in '" & vPath & "' is " & FileCnt, "MY E-MAIL SERVER"
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 = True
Exit Function
End If
With objCDO
.Subject = "File Count"
.From = "THEIR E-MAIL ADDRESS" 'address does not have to exist
.To = "MY E-MAIL ADDRESS"
.TextBody = strBody
With .Configuration.Fields
.Item(" = 2
.Item(" = SmtpServer
.Item(" = 25
.Update
End With
.Send
End With
Set objCDO = Nothing
SendMailCDO = True
End Function
So bottom line is I would like it to calculate the number of folders and files in the C:\GS folder and have it in the e-mail. Again currently all I see in the e-mail is "The Total Number of Files in C:\GS is XXX".
Any help would be honestly appreciated it!