Solved

"DateCreated" Script returning incorrect values

Posted on 2008-10-15
7
363 Views
Last Modified: 2012-05-05
Basically I am having to write a "work-around" script for some Software an Insurance House has provided us with that is playing up. So while they work on a proper fix I have thought of a work around to the problem.

Basically what is happening is their print monitor is crashing, the best way to solve this is to close it and restart the program which then starts pushing the documents through. This print monitor stores the documents in the Doc & Settings/App Data/%username%/....... area.

I am writing a script so that when a file in that folder is over 2 minutes old it automatically kills the print processor and then restarts it. This is to make sure that the document does get forced through.

The problem I have is no matter what I do the attached code counts the amount of files in the folder even if they were JUST created, and not over 2 minutes old. I think I need a set of far more experienced eyes to see if I am doing anything wrong, I am very new to this so I may have mis-understood something or overlooked something simple for that I apologise if so.

Cheers.
Set colFiles = oFolder.Files

      nFiles = colFiles.Count

 

      For Each oFile In colFiles

         If DateDiff("s", oFile.DateCreated, Now()) >= 120000 Then   '-- ensure file is at least 2 minutes old

         nFiles = colFiles.Count - 1                     '-- to avoid COUNTING NEW FILES

         End If

      Next

Open in new window

0
Comment
Question by:ADT58
  • 4
  • 2
7 Comments
 
LVL 29

Expert Comment

by:Badotz
ID: 22721291
If the date created is greater than 120000, you subtract 1 crom the count of files. This is the problem. Try this:

If DateDiff("s", oFile.DateCreated, Now()) <= 120000 Then   '-- ensure file is at least 2 minutes old
0
 

Author Comment

by:ADT58
ID: 22721555
nope still counting files, that have JUST been created and not files that are over 2 minutes (120000 seconds) old. :( can't get my head around this.
0
 
LVL 29

Accepted Solution

by:
Badotz earned 25 total points
ID: 22721726
Do this:

If DateDiff("s", oFile.DateCreated, Now()) <= 120000 Then
    MsgBox oFile.DateCreated & vbCrLf & Now() & vbCrLf & DateDiff("s", oFile.DateCreated, Now())
    nFiles = colFiles.Count - 1
End If

See if you can determine anything from that.

Alternatively, you could step through the code with a debugger and examine things during run-time.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 18

Assisted Solution

by:exx1976
exx1976 earned 25 total points
ID: 22722023
This is an easy one.  :-)  Here's the solution:


Set colFiles = oFolder.Files
nFiles = 0
For Each oFile In colFiles
    If DateDiff("s", oFile.DateCreated, Now()) >= 120000 Then nFiles = nFiles + 1
Next
wscript.echo(nFiles)


The way it was written, it would ALWAYS return the number of files, minus one.  you weren't actually decrementing your counter, you were just always setting it to colfiles.count - 1


Give this a shot and let us know.  It should spit out the number of files older than 2 minutes.

-exx
0
 
LVL 29

Expert Comment

by:Badotz
ID: 22722115
Well, DUH on me ;-)
0
 

Author Comment

by:ADT58
ID: 22722164
Well at first thanks to Badotz I realised that I was trying to count the impossible with the DateDiff, I think because I was asking it to work out the Different Betwen xx/xx/xx xx:xx:xx and xx/xx/xx xx:xx:xx, I was asking it to work it all out by seconds (120000) instead I changed the "s" to "m" and worked it out by stating:

If DateDiff("m", oFile.DateCreated, Now()) >= 2

So Badotz made me realise something I was completely overlooking and then yours exx was a complete solution obvious on the fact I changed the "s" to "m" and the 120000 to 2 again and it works fine.

Cheers to you both, not only do I have a solution but I also learned something which was a win win.
0
 
LVL 29

Expert Comment

by:Badotz
ID: 22722252
Strive to learn one new thing a day, I always say. Good job!

Oh, and no worries - glad to help.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

706 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now