Solved

Create Date on File

Posted on 2008-06-24
4
733 Views
Last Modified: 2008-07-10
Hi,

I have a vbscript that searches log files for certain words.  On each run of the script information is written to a file called letter_print_extract.txt.  What I want to do is if the letter_print_extract.txt file is more than 5 days old I want to move it to a new file name and re-create it again.

To do this I'm using the code :-

'Rename existing file based on modified date of previous log file
        Set SecureLogFile = objFSOLog.GetFile(strFullLogPath)
        CreatedDate = SecureLogfile.DateCreated
        ModifiedDate = SecureLogfile.DateLastModified

        If CreatedDate <= SecureDate Then
          objFSOLog.MoveFile strFullLogPath, strFullBackupPath & "_" & FormatDateToString(ModifiedDate)  & ".txt"
        End If        

This works fine, so I then want to re-create a new file with the same name as the one just moved.
Again this works, but the DateCreated does not show as 24th June but as 2nd June which is when the original was created.

To create the file I use

        Set objFSOLog = CreateObject("Scripting.FileSystemObject")
        Set LogFile = objFSOLog.OpenTextFile(strFullLogPath, ForAppending, TRUE)

The create date of this file is still 2nd June 2008.

Any ideas what I'm doing wrong. Have attached the full script for completeness.
0
Comment
Question by:HRMorton
  • 2
  • 2
4 Comments
 
LVL 15

Accepted Solution

by:
dosth earned 100 total points
ID: 21854244
yes, DateCreated is always when the file is created first time

instead of checking this

If CreatedDate <= SecureDate Then

can you check for ModifiedDate <= now()-5
0
 
LVL 24

Assisted Solution

by:purplepomegranite
purplepomegranite earned 25 total points
ID: 21854254
That is odd, and I wonder if it is to do with using OpenTextFile.

Try the attached modification and see if that does the same.
Set objFSOLog = CreateObject("Scripting.FileSystemObject")
if objFSOLog.FileExists(strFullLogPath) then
   Set LogFile = objFSOLog.OpenTextFile(strFullLogPath, ForAppending) 
else
   Set LogFile = objFSOLog.CreateTextFile(strFullLogPath, ForAppending, false) 
end if

Open in new window

0
 
LVL 24

Expert Comment

by:purplepomegranite
ID: 21854278
Actually, having just checked, that is right.  If I delete a file in Windows Explorer, then create one with the same name, it retains the created date of the original file.

You could modify the log so that the first line when you recreate it is the log start date.  Then you can read this line to determine when to archive it.  Using the ModifiedDate value won't work, because it will always be recently modified as your script updates it!
0
 
LVL 15

Expert Comment

by:dosth
ID: 21971110
thanks for the points
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

This is an addendum to the following article: Acitve Directory based Outlook Signature (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24950055.html) The script is fine, and works in normal client-server domains…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

756 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