在C#.NET中,如何将文件复制到另一个位置,如果源文件比现有文件新(具有较晚的“修改日期”),则覆盖现有文件,如果源文件较旧,如何进行注释?
发布于 2012-12-27 18:02:41
您可以使用FileInfo
class及其属性和方法:
FileInfo file = new FileInfo(path);
string destDir = @"C:\SomeDirectory";
FileInfo destFile = new FileInfo(Path.Combine(destDir, file.Name));
if (destFile.Exists)
{
if (file.LastWriteTime > destFile.LastWriteTime)
{
// now you can safely overwrite it
file.CopyTo(destFile.FullName, true);
}
}
发布于 2012-12-27 18:02:25
您可以使用FileInfo类:
FileInfo infoOld = new FileInfo("C:\\old.txt");
FileInfo infoNew = new FileInfo("C:\\new.txt");
if (infoNew.LastWriteTime > infoOld.LastWriteTime)
{
File.Copy(source path,destination path, true) ;
}
发布于 2012-12-27 18:05:01
在批处理文件中,这将起作用:
XCopy "c:\my directory\source.ext" "c:\my other directory\dest.ext" /d
https://stackoverflow.com/questions/14052661
复制相似问题