C# 如果文件名放置到目录不起作用
我有一个小问题…我正在编写自动更新程序,当我下载.exe文件时,我想把它放到main dir..和others.extension到sub dir File.exe=这里是我下载到主目录的地方 Else=放置到子目录…但它不工作,请将所有内容放置到主目录C# 如果文件名放置到目录不起作用,c#,filenames,if-statement,C#,Filenames,If Statement,我有一个小问题…我正在编写自动更新程序,当我下载.exe文件时,我想把它放到main dir..和others.extension到sub dir File.exe=这里是我下载到主目录的地方 Else=放置到子目录…但它不工作,请将所有内容放置到主目录 if(ex[1] == "File.exe") { if (File.Exists(path)) { if(File.Exists(String.Format("{0}WoW.exe", wow.GetValue
if(ex[1] == "File.exe")
{
if (File.Exists(path))
{
if(File.Exists(String.Format("{0}WoW.exe", wow.GetValue("InstallPath").ToString())))
{
File.Copy(String.Format("{0}WoW.exe", wow.GetValue("InstallPath").ToString()), String.Format("{0}WoW_zaloha_Awrodar_old_file.exe", wow.GetValue("InstallPath").ToString()), false);
File.Delete(String.Format("{0}WoW.exe", wow.GetValue("InstallPath").ToString()));
}
else if(File.Exists(String.Format("{0}Wow.exe", wow.GetValue("InstallPath").ToString())))
{
File.Copy(String.Format("{0}Wow.exe", wow.GetValue("InstallPath").ToString()), String.Format("{0}Wow_zaloha_Awrodar_old_file.exe", wow.GetValue("InstallPath").ToString()), false);
File.Delete(String.Format("{0}Wow.exe", wow.GetValue("InstallPath").ToString()));
}
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
MD5 md5 = new MD5CryptoServiceProvider();
byte[] retVal = md5.ComputeHash(fs);
fs.Close();
StringBuilder sb = new StringBuilder();
foreach(byte b in retVal)
sb.Append(string.Format("{0:X2}", b));
if(ex[2] == sb.ToString())
proceed = false;
}
}
else
{
if(File.Exists(MPQpath))
{
FileStream fs = new FileStream(MPQpath, FileMode.Open, FileAccess.Read, FileShare.Read);
MD5 md5 = new MD5CryptoServiceProvider();
byte[] retVal = md5.ComputeHash(fs);
fs.Close();
StringBuilder sb = new StringBuilder();
foreach(byte b in retVal)
sb.Append(string.Format("{0:X2}", b));
if(ex[2] == sb.ToString())
proceed = false;
}
}
使用
Path.combined
进行路径操作,以确保文件名的正确性。除此之外,我不知道你的代码有什么问题。您是否追踪了它以找出导致您的问题的原因。请详细说明“不起作用”?这并没有告诉我们问题出在哪里。