Re: File.datecreated doesn't change
- From: "James Whitlow" <jwhitlow.60372693@xxxxxxxxxxxxx>
- Date: Sun, 14 Sep 2008 03:55:44 -0500
"Todd Vargo" <tlvargo@xxxxxxxxxxxxxx> wrote in message
news:eIruFKhFJHA.3288@xxxxxxxxxxxxxxxxxxxxxxx
Todd Vargo wrote:
mayayana wrote:in
filePersonally, I still consider this undesirable behavior. If I delete a
and recreate another with the same name ten seconds later, it is not,
themy
opinion an update version of the previous
Yes, if *you* delete it. But if you edit the file
in an editor then it's technically being deleted,
in most cases, and re-written a moment later.
If you define that as a new file then date created
and date modified would always be the same.
That depends on how the editor was written. In many cases applications
are
written to protect the original file until the new one is written
successfully. After a successful write, the original file is deleted and
new renamed to the original name (or - rename first, create the new file,was
then delete the old).
But WSH/VBScript is not an editor and does not provide a Binary or Random
access mode so I would expect that the CreateTextFile method would delete
the existing file without needing a proceeding DeleteFile (as OP's code
uses). Basically, OP explicitly wrote the code to delete the file and it
not completely removed from the file system. As I mentioned, I do not
have
this issue in Windows 98 (FAT32). Perhaps it's an OS specific caching or
file system abnormality.
Ok, I did some more testing...
I see the behavior the OP described in Windows 98 but only if I remove the
fso.DeleteFile ("c:\testfile.txt") line. This indicates (to me) that under
the hood, CreateTextFile opens existing files in sort of a binary mode.
That
makes me wonder why they never provided a binary mode which script writers
could use. It would sure be nice to not have to write an entire file every
time you wanted to just change a single or few characters.
As far as the OP's situation goes, if DateCreated tag is not changing even
with using the DeleteFile method, then renaming the file before deletion
may
solve the problem.
Dim fso, MyFile
on error resume next
Set fso = CreateObject("Scripting.FileSystemObject")
fso.MoveFile "c:\testfile.txt", "c:\testfile.txt.del"
fso.DeleteFile "c:\testfile.txt.del"
Set MyFile = fso.CreateTextFile("c:\testfile.txt", True)
MyFile.WriteLine("This is a test.")
MyFile.Close
I tried this out in Windows XP and it unfortunately did not change the
outcome. My 'Date Created' is still from 2 days ago. I even added a
'WScript.Sleep 10000' after file deletion and ran it a second time to make
sure the file really was being deleted before being recreated.
I had also tried something similar using 'MoveFile'. I first deleted the
original file, waited 5 seconds, created a new file with a different name,
waited 5 seconds, moved the new file to the old filename. I put the pauses
in so I could watch things actually happening. When run, I see the original
file disappear, I see the new filename appear and see the rename happen.
After all this, the 'Date Created' remains the same.
During the above test, I turned on the 'Date Created' column in my
details view. The 'Date Created' for 'testfile2.txt' is accurate, but
reverts to the old date as soon as it is renamed.
It sounds like Microsoft had this working more intuitively in Windows 98
than in Windows XP.
Dim fso, MyFile
on error resume next
Set fso = CreateObject("Scripting.FileSystemObject")
fso.DeleteFile ("c:\testfile.txt")
WScript.Sleep 5000
Set MyFile = fso.OpenTextFile("c:\testfile2.txt", 2, True)
MyFile.WriteLine("This is a test2.")
MyFile.Close
WScript.Sleep 5000
fso.movefile "c:\testfile2.txt", "c:\testfile.txt"
.
- Follow-Ups:
- Re: File.datecreated doesn't change
- From: Todd Vargo
- Re: File.datecreated doesn't change
- References:
- File.datecreated doesn't change
- From: Todd Heiks
- Re: File.datecreated doesn't change
- From: Todd Vargo
- Re: File.datecreated doesn't change
- From: Al Dunbar
- Re: File.datecreated doesn't change
- From: James Whitlow
- Re: File.datecreated doesn't change
- From: Joe Fawcett
- Re: File.datecreated doesn't change
- From: mayayana
- Re: File.datecreated doesn't change
- From: Al Dunbar
- Re: File.datecreated doesn't change
- From: mayayana
- Re: File.datecreated doesn't change
- From: Todd Vargo
- Re: File.datecreated doesn't change
- From: Todd Vargo
- File.datecreated doesn't change
- Prev by Date: Re: File.datecreated doesn't change
- Next by Date: Re: File.datecreated doesn't change
- Previous by thread: Re: File.datecreated doesn't change
- Next by thread: Re: File.datecreated doesn't change
- Index(es):
Relevant Pages
|