Hey guys, I'm new to vbs. (Don't they all say that?) I'm trying to automate a
task at work using vbs. Basically, I need a count of files from a folder AND
sub-folders for all .pdf files created today. The path is Z:\C89\ and it
remains constant and the file names are formatted as such: xxxx20070518.pdf,
where the current date + 5 days is embedded into the file name. (I can't get
the wildcard to work-that's why I thought I'd mention it.) Next, I'd like for
the script to send me the results in an email. e.g. "The C89 folder has 50
pdf files" We use Windows Exchange on XP/2003 here. I've tried to piece
together code from different sites, but I always end up with some error. I
don't mind cracking open a book and learning vbs from scratch-which I intend
to do, but I'm up against a deadline.
Regards~

Re: Search for Files by creation date by Ayush

Ayush
Sun May 13 22:00:38 CDT 2007

[austinboy01]s message :
> Hey guys, I'm new to vbs. (Don't they all say that?) I'm trying to automate a
> task at work using vbs. Basically, I need a count of files from a folder AND
> sub-folders for all .pdf files created today. The path is Z:\C89\ and it
> remains constant and the file names are formatted as such: xxxx20070518.pdf,
> where the current date + 5 days is embedded into the file name. (I can't get
> the wildcard to work-that's why I thought I'd mention it.) Next, I'd like for
> the script to send me the results in an email. e.g. "The C89 folder has 50
> pdf files" We use Windows Exchange on XP/2003 here. I've tried to piece
> together code from different sites, but I always end up with some error. I
> don't mind cracking open a book and learning vbs from scratch-which I intend
> to do, but I'm up against a deadline.
> Regards~


folder="Z:\C89"
ext=".pdf"

Set fs=CreateObject("Scripting.FileSystemObject")
list=""
LoopFiles fs.GetFolder(folder)
On Error Resume Next
Sub LoopFiles(Folder)
For Each File in Folder.Files
If Right(File.Name,Len(ext))=ext Then
If DateDiff("d",File.DateCreated,Now)=0 Then
list=list & File.Path & vbNewLine
End If
End If
Next
For Each SubFolder in Folder.SubFolders
LoopFiles SubFolder
Next
End Sub

msgbox list

Set cdm = CreateObject("CDO.Message")
cdm.Subject = "SUBJECT HERE"
cdm.From = "ENTER FROM HERE"
cdm.To = "TO HERE"
cdm.TextBody = list
cdm.Send

Good Luck, Ayush.
--
VBScript, JScript, WSH Reference : http://www.devguru.com/

Re: Search for Files by creation date by austinboy01

austinboy01
Sun May 13 23:08:06 CDT 2007

Thank You Ayush! This is the most progress I've made thanks to you! Two things:
1. The folders/sub folders will have over 20,000 of these .pdf files. How do
I edit your code to only give me a count and write a statement on the
list/e-mail to say something like: "There are 23,269 pdf files in the Z:\C89
folder"

2. The email portion didn't work. Do I need to include our mail server name
in the cdo.message part such as: cdm.From =
"al.garcia@servername.companyname.net"

Woo Hoo!


"Ayush" <"ayushmaan.j[aatt]gmail.com" wrote:

> [austinboy01]s message :
> > Hey guys, I'm new to vbs. (Don't they all say that?) I'm trying to automate a
> > task at work using vbs. Basically, I need a count of files from a folder AND
> > sub-folders for all .pdf files created today. The path is Z:\C89\ and it
> > remains constant and the file names are formatted as such: xxxx20070518.pdf,
> > where the current date + 5 days is embedded into the file name. (I can't get
> > the wildcard to work-that's why I thought I'd mention it.) Next, I'd like for
> > the script to send me the results in an email. e.g. "The C89 folder has 50
> > pdf files" We use Windows Exchange on XP/2003 here. I've tried to piece
> > together code from different sites, but I always end up with some error. I
> > don't mind cracking open a book and learning vbs from scratch-which I intend
> > to do, but I'm up against a deadline.
> > Regards~
>
>
> folder="Z:\C89"
> ext=".pdf"
>
> Set fs=CreateObject("Scripting.FileSystemObject")
> list=""
> LoopFiles fs.GetFolder(folder)
> On Error Resume Next
> Sub LoopFiles(Folder)
> For Each File in Folder.Files
> If Right(File.Name,Len(ext))=ext Then
> If DateDiff("d",File.DateCreated,Now)=0 Then
> list=list & File.Path & vbNewLine
> End If
> End If
> Next
> For Each SubFolder in Folder.SubFolders
> LoopFiles SubFolder
> Next
> End Sub
>
> msgbox list
>
> Set cdm = CreateObject("CDO.Message")
> cdm.Subject = "SUBJECT HERE"
> cdm.From = "ENTER FROM HERE"
> cdm.To = "TO HERE"
> cdm.TextBody = list
> cdm.Send
>
> Good Luck, Ayush.
> --
> VBScript, JScript, WSH Reference : http://www.devguru.com/
>

Re: Search for Files by creation date by Ayush

Ayush
Mon May 14 07:21:36 CDT 2007

[austinboy01]s message :
> Thank You Ayush! This is the most progress I've made thanks to you! Two things:
> 1. The folders/sub folders will have over 20,000 of these .pdf files. How do
> I edit your code to only give me a count and write a statement on the
> list/e-mail to say something like: "There are 23,269 pdf files in the Z:\C89
> folder"

folder="Z:\C89"
ext=".pdf"

Set fs=CreateObject("Scripting.FileSystemObject")
list=0
LoopFiles fs.GetFolder(folder)
On Error Resume Next
Sub LoopFiles(Folder)
For Each File in Folder.Files
If Right(File.Name,Len(ext))=ext Then
If DateDiff("d",File.DateCreated,Now)=0 Then
list=list +1
End If
End If
Next
For Each SubFolder in Folder.SubFolders
LoopFiles SubFolder
Next
End Sub

msgbox "There are " & list & " pdf files in the " & folder & "folder."

the EMAIL part.


> 2. The email portion didn't work. Do I need to include our mail server name
> in the cdo.message part such as: cdm.From =
> "al.garcia@servername.companyname.net"

Sorry, I dont know about that. I just copied the EMail part from a website.


Good Luck, Ayush.
--
Regular Expression Syntax : http://snipurl.com/RegularExpr_Syntax

Re: Search for Files by creation date by austinboy01

austinboy01
Mon May 14 08:50:01 CDT 2007

Thank you again, Ayush. You've helped me get further than anyone else. Are
there any good books that you recommend for VBScript?

al in austin tx. :D




"Ayush" <"ayushmaan.j[aatt]gmail.com" wrote:

> [austinboy01]s message :
> > Thank You Ayush! This is the most progress I've made thanks to you! Two things:
> > 1. The folders/sub folders will have over 20,000 of these .pdf files. How do
> > I edit your code to only give me a count and write a statement on the
> > list/e-mail to say something like: "There are 23,269 pdf files in the Z:\C89
> > folder"
>
> folder="Z:\C89"
> ext=".pdf"
>
> Set fs=CreateObject("Scripting.FileSystemObject")
> list=0
> LoopFiles fs.GetFolder(folder)
> On Error Resume Next
> Sub LoopFiles(Folder)
> For Each File in Folder.Files
> If Right(File.Name,Len(ext))=ext Then
> If DateDiff("d",File.DateCreated,Now)=0 Then
> list=list +1
> End If
> End If
> Next
> For Each SubFolder in Folder.SubFolders
> LoopFiles SubFolder
> Next
> End Sub
>
> msgbox "There are " & list & " pdf files in the " & folder & "folder."
>
> the EMAIL part.
>
>
> > 2. The email portion didn't work. Do I need to include our mail server name
> > in the cdo.message part such as: cdm.From =
> > "al.garcia@servername.companyname.net"
>
> Sorry, I dont know about that. I just copied the EMail part from a website.
>
>
> Good Luck, Ayush.
> --
> Regular Expression Syntax : http://snipurl.com/RegularExpr_Syntax
>

Re: Search for Files by creation date by Ayush

Ayush
Mon May 14 08:42:18 CDT 2007

[austinboy01]s message :
> Thank you again, Ayush. You've helped me get further than anyone else

You are welcome !


> Are
> there any good books that you recommend for VBScript?

I use this: http://snipurl.com/WSH_Documentation





Good Luck, Ayush.
--
VBScript Language Reference : http://snipurl.com/VBScript_Reference

Re: Search for Files by creation date by austinboy01

austinboy01
Mon May 14 10:02:02 CDT 2007

I'll try to work the code to copy the msg "there are xxx number of pdf's...."
to a text file. From there, I think I could use a regular batch script to
email the body of the text.

You 'da man, Ayush!

al

"Ayush" <"ayushmaan.j[aatt]gmail.com" wrote:

> [austinboy01]s message :
> > Thank you again, Ayush. You've helped me get further than anyone else
>
> You are welcome !
>
>
> > Are
> > there any good books that you recommend for VBScript?
>
> I use this: http://snipurl.com/WSH_Documentation
>
>
>
>
>
> Good Luck, Ayush.
> --
> VBScript Language Reference : http://snipurl.com/VBScript_Reference
>

Re: Search for Files by creation date by Ayush

Ayush
Mon May 14 11:14:57 CDT 2007

[austinboy01]s message :
> I'll try to work the code to copy the msg "there are xxx number of pdf's...."
> to a text file. From there, I think I could use a regular batch script to
> email the body of the text.

If you are using Batch script then try this to count the pdf files:
:::::::::::::::::::::
set counter=0
for /f %f in ('dir Z:\C89\*.pdf /b /s') do @set /a counter=counter+1
echo There are %counter% pdf files in Z:\C89 folder.
:::::::::::::::::::::

Good Luck, Ayush.
--
VBScript, JScript, WSH Reference : http://www.devguru.com/