I'm currently working on a simple winforms renamer and I cannot find out how to fix IF containing !File.Exists, since when I press the second button and go back to the first one it will just do both the IF and ELSE and I have no idea why.
This is the code that is giving me a trouble:
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";
}
}
The code checks if German file doesn't exist and by that it determines that the voice file is currently in German so it tries to change to French, that works fine but when I do this multiple times between first IF and second IF it still renames the files fine but both the IF and ELSE complete which is weird to me, so the label just keeps on saying Game already in French/German depending on which radio I click.
My problem was in radios being executed twice, and not anything to do with File.Exists, thanks for all the help