Solved

Create Date on File

Posted on 2008-06-24
4
729 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
thanks for the points
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
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 demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

728 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

14 Experts available now in Live!

Get 1:1 Help Now