Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 复制文件后未更新修改日期_C# - Fatal编程技术网

C# 复制文件后未更新修改日期

C# 复制文件后未更新修改日期,c#,C#,我正在将文件夹及其所有内容(包括子目录和文件)导入我的应用程序数据目录,以供我的应用程序使用 我尝试过很多解决方案,但最有效的是这个 //Create all of the directories foreach (string dirPath in Directory.GetDirectories(SourcePath, "*", SearchOption.AllDirectories)) Directory.CreateDirectory(dirPath.Replace(SourcePat

我正在将文件夹及其所有内容(包括子目录和文件)导入我的应用程序数据目录,以供我的应用程序使用

我尝试过很多解决方案,但最有效的是这个

//Create all of the directories
foreach (string dirPath in Directory.GetDirectories(SourcePath, "*", 
SearchOption.AllDirectories))
Directory.CreateDirectory(dirPath.Replace(SourcePath, DestinationPath));

//Copy all the files & Replaces any files with the same name
foreach (string newPath in Directory.GetFiles(SourcePath, "*.*", 
SearchOption.AllDirectories))
File.Copy(newPath, newPath.Replace(SourcePath, DestinationPath), true);

这非常有效,但如果文件已存在于目标目录中,则会更新其数据,但其修改日期根本不会更新。

复制文件时,修改日期永远不会更新,文件没有更改,只是位置而已。

您如何检查修改日期?这没有意义,我能看一张截图吗?当然,您可以先执行删除操作,但存在一个问题,即Windows文件系统不反映审核更改。我还需要查看文件/文件夹权限以及运行此代码的用户。这听起来不对。我发现很难相信文件的内容会在没有设置时间戳的情况下得到更新。explorer是否正在缓存它?复制文件时,修改的日期永远不会更新,文件没有更改,只是更改了位置。