Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the file creation date does not work

Tags:

I'm using the following to change the creation date of a text file:

using System.IO;  ... DateTime newCreate = new DateTime(year, month, day, hour, minutes, seconds); File.SetCreationTime("changemydate.txt", newCreate); 

However this doesn't do anything. There is no error message, yet it doesn't change the date of the file at all.

I tried this in a dropbox folder as well as in a random folder without success

The DateTime newCreate object seems to be correct though.

It would be great if somebody could point me to an idea...

like image 418
pandita Avatar asked Jun 15 '13 15:06

pandita


People also ask

Can file creation date be changed?

You can modify the date created by copying a file. The file's created date becomes the modified date and the current date (when the file is copied) becomes the created date. You can copy a file on your PC to check.

How can I change the modified date of a file?

You can manually change the Last Modified Date/Time for a file using a free software called Attribute Changer from http://www.petges.lu/. You will need to remember the modified date/time of your presentation file, modify the file and then use Attribute Changer to set the modified date/time to the previous one.


Video Answer


1 Answers

Actually, each file has three different times:

  1. Creation time
  2. Last access time
  3. Last write time (that's shown in Explorer and other file managers as "File Date")

To modify these times you can use

File.SetCreationTime(path, time); File.SetLastWriteTime(path, time); File.SetLastAccessTime(path, time); 

respectively.

It seems, that if you want to change file date as it shown in file manager (e.g. Explorer) you should try something like that:

String path = @"changemydate.txt";                 DateTime time = new DateTime(year, month, day, hour, minutes, seconds);   if (File.Exists(path))     File.SetLastWriteTime(path, time); 
like image 181
Dmitry Bychenko Avatar answered Sep 17 '22 15:09

Dmitry Bychenko