Solved

Create Date on File

Posted on 2008-06-24
4
731 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Recently I finished a vbscript that I thought I'd share.  It uses a text file with a list of server names to loop through and get various status reports, then writes them all into an Excel file.  Originally it was put together for our Altiris server…
Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
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…

821 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