Re: File.datecreated doesn't change



"Todd Vargo" <tlvargo@xxxxxxxxxxxxxx> wrote in message
news:eIruFKhFJHA.3288@xxxxxxxxxxxxxxxxxxxxxxx
Todd Vargo wrote:
mayayana wrote:
Personally, I still consider this undesirable behavior. If I delete a
file
and recreate another with the same name ten seconds later, it is not,
in
my
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
the
new renamed to the original name (or - rename first, create the new file,
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
was
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"


.



Relevant Pages

  • Re: File.datecreated doesnt change
    ... That depends on how the editor was written. ... the original file is deleted and the ... the existing file without needing a proceeding DeleteFile (as OP's code ... not completely removed from the file system. ...
    (microsoft.public.scripting.wsh)
  • Re: File.datecreated doesnt change
    ... Todd Vargo wrote: ... That depends on how the editor was written. ... CreateTextFile opens existing files in sort of a binary mode. ... with using the DeleteFile method, then renaming the file before deletion may ...
    (microsoft.public.scripting.wsh)
  • Re: Re (4): Is awk suitable for this?
    ... the human-user sees as redundant-garbage, and copies to the DeleteFile, ... before the editor contents is ... <save to InputFile and call CleanUpScript>. ... Empty the test inputFile: InF ...
    (comp.lang.awk)
  • RE: Vista Undeletable File Problem
    ... Did you unload the DLL? ... behavior with OPEN files. ... Windows allows you delete an open file - but the ... I delete the DLL when I am done with it, and the DeleteFile function ...
    (microsoft.public.platformsdk.security)
  • Schnelles Loeschen von gesperrten Dateien
    ... Wenn Windows eine Datei gesperrt hält ist es ja nicht ... es bis zu einer Sekunde bis Windows bis "DeleteFile" fehlschlägt. ... Das will ich beschleunigen. ...
    (de.comp.lang.delphi.misc)