I have a very strange problem! I wonder if there is a problem within the OS, or maybe it's just me, a misunderstanding of things ...
I have a file that can be created long ago, I use this file, and then I want to archive it by changing its name. Then I want to create a new file with the same name as the old file, before renaming it. Easy enough!
The problem that really puzzles me is that the newly created file mistakenly "created" -timestamp! This is a problem because it is a timestamp that I want to use to determine when to archive and create a new file.
I created a very small sample that shows the problem. For the sample to work, the 1.txt file must be in the Files folder. In addition, the file attribute must also be set in time (with one of the tools available, I use Nomad.NET).
static void Main(string[] args) { // Create a directory, if doesnt exist. string path = Path.GetDirectoryName(Application.ExecutablePath) + "\\Files"; Directory.CreateDirectory(path); // Create/attach to the 1.txt file string filename = path + "\\1.txt"; StreamWriter sw = File.AppendText(filename); sw.WriteLine("testing"); sw.Flush(); sw.Close(); // Rename it... File.Move(filename, path + "\\2.txt"); // Create a new 1.txt sw = File.AppendText(filename); FileInfo fi = new FileInfo(filename); // Observe, the old files creation date!! Console.WriteLine(String.Format("Date: {0}", fi.CreationTime.Date)); Console.ReadKey(); }
kaze Jan 21 '10 at 12:35 on 2010-01-21 12:35
source share