令人难以置信的怪文件的创建时间问题令人难以置信、文件、时间、问题

2023-09-03 00:03:44 作者:Autism(孤独症)

我有一个很奇怪的问题真的!我不知道问题出在框架,操作系统或也许这只是我,误会的事情...

我有一个文件,它可能会创建一个很久以前,我用的文件,然后我想存档,通过改变它的名字。然后,我想创建一个新的文件,具有相同名称的旧文件了,它被重新命名了。很容易!

这真的让我为难的问题是,新创建的文件得到错误的创建-timestamp!这是一个问题,因为它是该时间戳,我想使用determing何时存档并创建一个新的文件。

我已经创建了一个非常小的样本,显示了问题。对于示例工作,必须有在Files文件夹中的文件1.txt的。另外,文件属性也必须设置时光倒流(带的工具之一可用,我用Nomad.NET)。

 静态无效的主要(字串[] args)
    {
        //创建一个目录,如果犯规存在。
        字符串路径= Path.GetDirectoryName(Application.ExecutablePath)+\\文件;
        Directory.CreateDirectory(路径);

        //创建/附加到的1.txt文件
        字符串文件名=路径+\\ 1.txt的;
        StreamWriter的SW = File.AppendText(文件名);
        sw.WriteLine(测试);
        sw.Flush();
        sw.Close();
        //将其重命名...
        File.Move(文件名,路径+\\ 2.txt);

        //创建一个新的1.txt
        SW = File.AppendText(文件名);
        FileInfo的F1 =新的FileInfo(文件名);
        //注意,旧的文件创建日期!
        Console.WriteLine(的String.Format(日期:{0},fi.CreationTime.Date));

        Console.ReadKey();
    }
 

解决方案 令人难以置信 灾难一周了还埋着145人,拜登这就夸上了

这是一个神秘的功能走出去的方式返回到Windows昔日的结果。核心详情请看这里:

的Windows NT包含文件系统隧道功能

基本上,这是故意的。但它的配置,和不合时宜的今天大多数的软件。

我的认为的,你可以先创建一个新的文件名,然后重命名OLD-> old.1,然后新建 - >老了,它会工作。我不记得说实话我们所做的事情,当我们碰到了这最后的几年前。

I have a very strange problem indeed! I wonder if the problem is in the framework, OS or maybe it's just me, misunderstanding things...

I have a file, which might be created a long time ago, I use the file, and then I want to archive it, by changing it's name. Then I want to create a new file, with the same name as the old file had, before it was renamed. Easy enough!

The problem that really puzzles me, is that the newly created file gets wrong "created"-timestamp! That's a problem since it's that timestamp that I want to use for determing when to archive and create a new file.

I've created a very small sample that shows the problem. For the sample to work, there must be a file 1.txt in the Files folder. Also, the file attribute must also be set back 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();
    }

解决方案

This is the result of an arcane "feature" going way back to the old days of Windows. The core details are here:

Windows NT Contains File System Tunneling Capabilities

Basically, this is on purpose. But it's configurable, and an anachronism in most of today's software.

I think you can create a new filename first, then rename old->old.1, then new->old, and it'll "work". I don't remember honestly what we did when we ran into this last a few years back.