Solved

"DateCreated" Script returning incorrect values

Posted on 2008-10-15
7
365 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

789 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