如果文件名放置到目录不起作用

发布于 2025-01-08 19:12:50 字数 1915 浏览 4 评论 0原文

我有一些小问题......我编码自动更新程序,当我下载 .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

々眼睛长脚气 2025-01-15 19:12:50

使用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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文