Wrong Creation Date for Files

S

Steven Blair

Hi,

I have a trace log file for a system I am writing. If the creation date
is older than 14 days, I have to rename that file (File.Move). The next
time a trace message is required a new file is created

StreamWriter sw = new StreamWriter(path,true);

The problem is, the creation date of this new file has the creation date
of the previous log file :S and not the present date.

I used a freeware app to change the creation date of the original file.

The new file definately does not exists before creation (File.Exist is
used)

Any help / comments on this would be appreciated.

Regards,

Steven



*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 
M

Morten Wennevik

Hi Steven,

Can't say why the creation date is stored. It may be that this is linked to another weird file "bug" using Directory.Create("Fold1"), Directory.Move("Fold1", "Fold2") and Directory.Delete("Fold2"). For some weird reason "Fold1" pops up when "Fold2" is deleted.

You could try setting the creation date manually using File.Set/Get-CreationTime/Attributes.
 
M

mikeb

Steven said:
Hi,

I have a trace log file for a system I am writing. If the creation date
is older than 14 days, I have to rename that file (File.Move). The next
time a trace message is required a new file is created

StreamWriter sw = new StreamWriter(path,true);

The problem is, the creation date of this new file has the creation date
of the previous log file :S and not the present date.

I used a freeware app to change the creation date of the original file.

The new file definately does not exists before creation (File.Exist is
used)

This is due to a feature of the operating system, called tunneling, to
support applications that create file backups by renaming a file (for
example to *.bak), then create a new file with the original name or some
similar variation on that theme. This way the filesystem maintains the
original file's 'state' in the new file (which *is* the original file
as far as the user is concerned).

See KB172190 for more information:

http://support.microsoft.com/default.aspx?scid=kb;en-us;172190
 
S

Steven Blair

Thanks for the reply.

Done a little more investigation and I can replicate the problem exactly
without using .NET.

I use Windows Explorer to delete the file, followed by creating a new
file with the same name as before. Guess what?, Windows sets the
Creation date to the previous date of the file lol

This has been a VERY long day lol

Regards,

Steven



*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top