Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

After deleting file and re-creating file, not change creation date in windows

Tags:

c#

file

I have c# application. This write log in folder.

below code.

if (File.Exists(@"C:\EXT_LOG\LOG.txt"))
{
    File.Delete(@"C:\EXT_LOG\LOG.txt");
}

string Data = "xxxxx";
System.IO.StreamWriter file = new StreamWriter(@"C:\EXT_LOG\LOG.txt");
file.WriteLine(Data);
file.Dispose();
file.Close();

I delete file, if it exist, and I create file with same name. when I run program, the creation date of file is not change.

I guess windows any manager or any file table still contain that file.

So, when I delete file, can I delete manager or file table content??

like image 276
T.K S Avatar asked Oct 20 '15 02:10

T.K S


People also ask

What happens when you change the file date ‘created’?

This change of the file date ‘Created’ can have the unusal side effect that the new ‘creation date’ of a file is more recent than the ‘modification date’ provided by the system. 2. What File Dates Do We Distinguish? The date taken (year / date / time) is created when a picture is taken or a video recorded.

How do I remove the date of creation from a file?

Right-click the file and press Properties. In the Properties box, press the Details tab, then click the Remove Properties and Personal Information option link. As we’ve mentioned, you can’t remove or change the file creation date or other essential file attributes here.

How to change the creation date of a Word document?

This generates a file properties window in which you can adjust the creation date of your file and other custom configurations. You have to click on the “File Properties” and make sure the box next to Modify File Date and Time Stamps is checked to alter the formation date on the settings of the Word documents.

Why does Windows 10 keep changing the date of a file?

Possible reasons are: When copying files, Windows (as other operation systems do as well) modifies the original ‘creation date’ to the date of copying. When setting up a new PC, the date of data transfer to the new hard disk will be set as the new ‘creation date’.


1 Answers

That's how it works in windows. I have not searched Google for WHY. However it seems you can set the creation date of the file through C# using System.IO.File.SetCreationTime method.

public static void SetCreationTime(
    string path,
    DateTime creationTime
)

Source: https://msdn.microsoft.com/en-us/library/system.io.file.setcreationtime(v=vs.100).aspx

like image 72
Nikhil Vartak Avatar answered Oct 01 '22 18:10

Nikhil Vartak