C# 关于(如何将旧的.zip文件覆盖为新的.zip文件)文件是否存在
这是关于我的问题的问题 情景 我有2个文件夹,路径和目标文件夹 然后在目的地我已经有了一个旧的zip文件名(old.zip) 如果我重新复制同一个zip文件,它会说该文件已经存在 问题是。如何将旧的.zip文件覆盖为新的.zip文件C# 关于(如何将旧的.zip文件覆盖为新的.zip文件)文件是否存在,c#,C#,这是关于我的问题的问题 情景 我有2个文件夹,路径和目标文件夹 然后在目的地我已经有了一个旧的zip文件名(old.zip) 如果我重新复制同一个zip文件,它会说该文件已经存在 问题是。如何将旧的.zip文件覆盖为新的.zip文件 string filepath = @"C:\Users\orly.simbulan\Desktop\Path"; string[] files = System.IO.Directory.GetFiles(filepath, "*exp.zip",System.I
string filepath = @"C:\Users\orly.simbulan\Desktop\Path";
string[] files = System.IO.Directory.GetFiles(filepath, "*exp.zip",System.IO.SearchOption.TopDirectoryOnly);
if(files.Length > 0)
{
foreach(string file in files)
{
string result;
result = Path.GetFileName(file);
// my code
if (File.Exists(file))
{
var destination1 = @"C:\Users\orly.simbulan\Desktop\destination1\";
string destFile = System.IO.Path.Combine(destination1, result);
File.Copy(file, destFile, true);
//System.IO.File.Copy(file, destFile, true);
}
else
{
}
}
}
下面是问题示例图像
:
到目前为止你尝试了什么?如果(File.Exists(File)){var destination1=@“C:\Users\orly.simbulan\Desktop\destination1\”;字符串destFile=System.IO.Path.Combine(destination1,result),则某些代码将非常有用//我的代码;File.Copy(File,destFile,true);//System.IO.File.Copy(File,destFile,true);}出现了什么错误?没有错误。问题是这个方法没有用,我不知道为什么。我的新文件不会覆盖旧文件..所以,你做错了什么。您确定路径正确吗?//如果(File.Exists(File)){var destination1=@“C:\Users\orly.simbulan\Desktop\destination1\”;字符串destFile=System.IO.path.Combine(destination1,result),则显示我的代码;File.Copy(File,destFile,true);//System.IO.File.Copy(File,destFile,true);}File.Copy方法不覆盖我的旧文件。
File.Copy(path, destination, true);