After deleting file and re-creating file, not change creation date in windows
up vote
7
down vote
favorite
I have c# application. This write log in folder.
below code.
if (File.Exists(@"C:EXT_LOGLOG.txt"))
{
File.Delete(@"C:EXT_LOGLOG.txt");
}
string Data = "xxxxx";
System.IO.StreamWriter file = new StreamWriter(@"C:EXT_LOGLOG.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??
c# file
add a comment |
up vote
7
down vote
favorite
I have c# application. This write log in folder.
below code.
if (File.Exists(@"C:EXT_LOGLOG.txt"))
{
File.Delete(@"C:EXT_LOGLOG.txt");
}
string Data = "xxxxx";
System.IO.StreamWriter file = new StreamWriter(@"C:EXT_LOGLOG.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??
c# file
How and when are you retrieving the creation date? If it's just Windows Explorer, have you tried hitting F5 to refresh the view?
– Grant
Oct 20 '15 at 2:52
1
@GrantWinney Actually you can test this yourself from Windows Explorer. 1) Find an existing old file. 2) delete it 3) Create a new file with the same name 4) New file will have the same Created as per old file (assuming you do it sufficient quickly). See dotnetkid's answer below. I was surprised myself :)
– MickyD
Oct 20 '15 at 3:26
2
The reason for this is to enable safe save. Like what MS WORD does. When application programs auto save, they do not over-write files. Instead, they move old file, and create a replica new file. However, the new file needs to retain the attributes of old file including creation time. Refer to temp files you see with ~ sign before them, enabling hidden files to see this happening.
– SreekanthGS
Oct 20 '15 at 5:15
@Micky That is surprising! Didn't expect that behavior.
– Grant
Oct 20 '15 at 11:06
add a comment |
up vote
7
down vote
favorite
up vote
7
down vote
favorite
I have c# application. This write log in folder.
below code.
if (File.Exists(@"C:EXT_LOGLOG.txt"))
{
File.Delete(@"C:EXT_LOGLOG.txt");
}
string Data = "xxxxx";
System.IO.StreamWriter file = new StreamWriter(@"C:EXT_LOGLOG.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??
c# file
I have c# application. This write log in folder.
below code.
if (File.Exists(@"C:EXT_LOGLOG.txt"))
{
File.Delete(@"C:EXT_LOGLOG.txt");
}
string Data = "xxxxx";
System.IO.StreamWriter file = new StreamWriter(@"C:EXT_LOGLOG.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??
c# file
c# file
asked Oct 20 '15 at 2:50
T.K S
362
362
How and when are you retrieving the creation date? If it's just Windows Explorer, have you tried hitting F5 to refresh the view?
– Grant
Oct 20 '15 at 2:52
1
@GrantWinney Actually you can test this yourself from Windows Explorer. 1) Find an existing old file. 2) delete it 3) Create a new file with the same name 4) New file will have the same Created as per old file (assuming you do it sufficient quickly). See dotnetkid's answer below. I was surprised myself :)
– MickyD
Oct 20 '15 at 3:26
2
The reason for this is to enable safe save. Like what MS WORD does. When application programs auto save, they do not over-write files. Instead, they move old file, and create a replica new file. However, the new file needs to retain the attributes of old file including creation time. Refer to temp files you see with ~ sign before them, enabling hidden files to see this happening.
– SreekanthGS
Oct 20 '15 at 5:15
@Micky That is surprising! Didn't expect that behavior.
– Grant
Oct 20 '15 at 11:06
add a comment |
How and when are you retrieving the creation date? If it's just Windows Explorer, have you tried hitting F5 to refresh the view?
– Grant
Oct 20 '15 at 2:52
1
@GrantWinney Actually you can test this yourself from Windows Explorer. 1) Find an existing old file. 2) delete it 3) Create a new file with the same name 4) New file will have the same Created as per old file (assuming you do it sufficient quickly). See dotnetkid's answer below. I was surprised myself :)
– MickyD
Oct 20 '15 at 3:26
2
The reason for this is to enable safe save. Like what MS WORD does. When application programs auto save, they do not over-write files. Instead, they move old file, and create a replica new file. However, the new file needs to retain the attributes of old file including creation time. Refer to temp files you see with ~ sign before them, enabling hidden files to see this happening.
– SreekanthGS
Oct 20 '15 at 5:15
@Micky That is surprising! Didn't expect that behavior.
– Grant
Oct 20 '15 at 11:06
How and when are you retrieving the creation date? If it's just Windows Explorer, have you tried hitting F5 to refresh the view?
– Grant
Oct 20 '15 at 2:52
How and when are you retrieving the creation date? If it's just Windows Explorer, have you tried hitting F5 to refresh the view?
– Grant
Oct 20 '15 at 2:52
1
1
@GrantWinney Actually you can test this yourself from Windows Explorer. 1) Find an existing old file. 2) delete it 3) Create a new file with the same name 4) New file will have the same Created as per old file (assuming you do it sufficient quickly). See dotnetkid's answer below. I was surprised myself :)
– MickyD
Oct 20 '15 at 3:26
@GrantWinney Actually you can test this yourself from Windows Explorer. 1) Find an existing old file. 2) delete it 3) Create a new file with the same name 4) New file will have the same Created as per old file (assuming you do it sufficient quickly). See dotnetkid's answer below. I was surprised myself :)
– MickyD
Oct 20 '15 at 3:26
2
2
The reason for this is to enable safe save. Like what MS WORD does. When application programs auto save, they do not over-write files. Instead, they move old file, and create a replica new file. However, the new file needs to retain the attributes of old file including creation time. Refer to temp files you see with ~ sign before them, enabling hidden files to see this happening.
– SreekanthGS
Oct 20 '15 at 5:15
The reason for this is to enable safe save. Like what MS WORD does. When application programs auto save, they do not over-write files. Instead, they move old file, and create a replica new file. However, the new file needs to retain the attributes of old file including creation time. Refer to temp files you see with ~ sign before them, enabling hidden files to see this happening.
– SreekanthGS
Oct 20 '15 at 5:15
@Micky That is surprising! Didn't expect that behavior.
– Grant
Oct 20 '15 at 11:06
@Micky That is surprising! Didn't expect that behavior.
– Grant
Oct 20 '15 at 11:06
add a comment |
2 Answers
2
active
oldest
votes
up vote
5
down vote
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
3
As dotnetkid mentioned, this is the default windows behaviour. The reason for this behaviour can be found here: support.microsoft.com/en-us/kb/172190
– Don
Oct 20 '15 at 3:05
add a comment |
up vote
0
down vote
this is how I solve the problem:
File.WriteAllBytes(outFile, body);
File.SetCreationTimeUtc(outFile, DateTime.UtcNow);
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
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
3
As dotnetkid mentioned, this is the default windows behaviour. The reason for this behaviour can be found here: support.microsoft.com/en-us/kb/172190
– Don
Oct 20 '15 at 3:05
add a comment |
up vote
5
down vote
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
3
As dotnetkid mentioned, this is the default windows behaviour. The reason for this behaviour can be found here: support.microsoft.com/en-us/kb/172190
– Don
Oct 20 '15 at 3:05
add a comment |
up vote
5
down vote
up vote
5
down vote
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
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
answered Oct 20 '15 at 2:58
Nikhil Vartak
3,65121623
3,65121623
3
As dotnetkid mentioned, this is the default windows behaviour. The reason for this behaviour can be found here: support.microsoft.com/en-us/kb/172190
– Don
Oct 20 '15 at 3:05
add a comment |
3
As dotnetkid mentioned, this is the default windows behaviour. The reason for this behaviour can be found here: support.microsoft.com/en-us/kb/172190
– Don
Oct 20 '15 at 3:05
3
3
As dotnetkid mentioned, this is the default windows behaviour. The reason for this behaviour can be found here: support.microsoft.com/en-us/kb/172190
– Don
Oct 20 '15 at 3:05
As dotnetkid mentioned, this is the default windows behaviour. The reason for this behaviour can be found here: support.microsoft.com/en-us/kb/172190
– Don
Oct 20 '15 at 3:05
add a comment |
up vote
0
down vote
this is how I solve the problem:
File.WriteAllBytes(outFile, body);
File.SetCreationTimeUtc(outFile, DateTime.UtcNow);
add a comment |
up vote
0
down vote
this is how I solve the problem:
File.WriteAllBytes(outFile, body);
File.SetCreationTimeUtc(outFile, DateTime.UtcNow);
add a comment |
up vote
0
down vote
up vote
0
down vote
this is how I solve the problem:
File.WriteAllBytes(outFile, body);
File.SetCreationTimeUtc(outFile, DateTime.UtcNow);
this is how I solve the problem:
File.WriteAllBytes(outFile, body);
File.SetCreationTimeUtc(outFile, DateTime.UtcNow);
edited 17 hours ago
Mohammad
12.5k93158
12.5k93158
answered 18 hours ago
Ivo Tabakov
12
12
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f33227149%2fafter-deleting-file-and-re-creating-file-not-change-creation-date-in-windows%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
How and when are you retrieving the creation date? If it's just Windows Explorer, have you tried hitting F5 to refresh the view?
– Grant
Oct 20 '15 at 2:52
1
@GrantWinney Actually you can test this yourself from Windows Explorer. 1) Find an existing old file. 2) delete it 3) Create a new file with the same name 4) New file will have the same Created as per old file (assuming you do it sufficient quickly). See dotnetkid's answer below. I was surprised myself :)
– MickyD
Oct 20 '15 at 3:26
2
The reason for this is to enable safe save. Like what MS WORD does. When application programs auto save, they do not over-write files. Instead, they move old file, and create a replica new file. However, the new file needs to retain the attributes of old file including creation time. Refer to temp files you see with ~ sign before them, enabling hidden files to see this happening.
– SreekanthGS
Oct 20 '15 at 5:15
@Micky That is surprising! Didn't expect that behavior.
– Grant
Oct 20 '15 at 11:06