?
Solved

Create Date on File

Posted on 2008-06-24
4
Medium Priority
?
737 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 15

Accepted Solution

by:
dosth earned 400 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 100 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying 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

Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

743 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