如果文件名放置到目录不起作用
我有一些小问题......我编码自动更新程序,当我下载 .exe 文件时,我想将其放置到主目录......以及其他 .extension 到子目录。
File.exe = 这是我下载到主目录的位置 否则=放置到子目录...但它不起作用,将全部放置到主目录
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;
}
}
I have problem with small thing...i coding auto updater and when i downloading .exe file i want to place it to main dir..and others .extension to sub dir.
File.exe = Here is i download place to main dir
Else = place to sub dir...but it isnt working, place all to main dir
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;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
Path.Combine
进行路径操作以确保文件名的正确性。除此之外我不知道你的代码有什么问题。您是否追踪过它以找出哪条线导致了您的问题?Use
Path.Combine
for path manipulation to ensure correctness of filenames. Other than that I don't know what is wrong with your code. Have you traced it though to find out which line is causing your problem.