Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#File.Exists似乎记得该文件存在_C#_File_Move_Exists - Fatal编程技术网

C#File.Exists似乎记得该文件存在

C#File.Exists似乎记得该文件存在,c#,file,move,exists,C#,File,Move,Exists,我目前正在使用一个简单的winforms重命名器,我无法找到如何修复包含!存在,因为当我按下第二个按钮并返回到第一个按钮时,它将同时执行IF和ELSE,我不知道为什么 这是给我带来麻烦的代码: string french = readpath + "\\data\\Fallout4 - Voices_fr.ba2"; string german = readpath + "\\data\\Fallout4 - Voices_de.ba2"; string voices = readpath +

我目前正在使用一个简单的winforms重命名器,我无法找到如何修复包含!存在,因为当我按下第二个按钮并返回到第一个按钮时,它将同时执行IF和ELSE,我不知道为什么

这是给我带来麻烦的代码:

string french = readpath + "\\data\\Fallout4 - Voices_fr.ba2";
string german = readpath + "\\data\\Fallout4 - Voices_de.ba2";
string voices = readpath + "\\data\\Fallout4 - Voices.ba2";
if (French.Checked)
{
    if (!File.Exists(german))
    {
        try
        {
            File.Move(voices, german);
            File.Move(french, voices);
            label1.Text = "Game set to French";
        }

        catch
        {
            label1.Text = "file doesn't exist";
        }
    }
    else
    {
        label1.Text = "Game already in French";
    }

}

if (German.Checked)
{
    if (!File.Exists(french))
    {
        try
        {
            File.Move(voices, french);
            File.Move(german, voices);
            label1.Text = "Game set to German";
        }

        catch
        {
            label1.Text = "file doesn't exist";
        }
    }
    else
    {
        label1.Text = "Game already in German";
    }
}

代码检查德文文件是否不存在,并由此确定语音文件当前为德文,因此它尝试更改为法文,这很好,但当我在第一个if和第二个if之间多次这样做时,如果它仍然重命名文件,则会很好,但if和ELSE都已完成,这对我来说很奇怪,所以标签上总是说游戏已经用法语/德语了,这取决于我点击的收音机。

我的问题是收音机被执行了两次,与File.Exists无关,感谢所有的帮助

为什么不始终使用
\u de
\u fr
文件,并根据勾选的复选框将其复制到不固定名称?诚然,你不可能有你的“游戏已经在…”提示,但它们真的对你有用吗?你使用的是什么控制按钮或单选按钮?我的观点是-所有三个文件都存在于磁盘上。然后,不要移动一个副本来为另一个副本腾出空间,只需用您想要使用的语言版本覆盖未粘贴的副本即可。@Damien_the_unsiever是的,这会起作用,但是它需要在磁盘上多放一个3 GB的文件,所以我不希望这样做。一个分支的两个条件不可能在同一个线程中执行。您还有一些其他问题,但没有充分描述。很高兴您解决了这个问题!你的代码看起来很好,所以它真是个麻烦。