No overload for method move

So basically, I have a process that starts from user input in a textbox. But one of the arguments in the process contains a folder which the user has but has the be renamed. and only after it would be renamed it would start the process. So I got.

    private void button2_Click_1(object sender, EventArgs e)
    {
        if (File.Exists(@"{0}\@JonzieMegaModPack"))
        {
            ProcessStartInfo startInfo = new ProcessStartInfo();
            startInfo.FileName = textBox1.Text;
            startInfo.Arguments =
                string.Format(@"-window -useBE {1} -mod={0}\@CBA_A3", textBox2.Text, textBox3);
            Process.Start(startInfo);
        }
        else
        {
            Directory.Move(@"{0}\@Jonzie Mega Mod Pack", @"{0}\@JonzieMegaModPack", textBox2.Text);
            ProcessStartInfo startInfo = new ProcessStartInfo();
            startInfo.FileName = textBox1.Text;
            startInfo.Arguments =
                string.Format(@"-window -useBE {1} -mod={0}\@CBA_A3", textBox2.Text, textBox3);
            Process.Start(startInfo);
        }
    }

But in the else part, with Directory.Move I get the error saying: no overload for method 'Move' takes 3 arguments. I'm guessing because of the komma at then end for the {0}.

Jon Skeet
people
quotationmark

Yes, you're calling Directory.Move, which only has one overload, with two string parameters. It's not clear why/how you expected that to work.

I suspect you're missing calls to string.Format, e.g.

string source = string.Format(@"{0}\@Jonzie Mega Mod Pack", textBox2.Text);
string destination = string.Format(@"{0}\@JonzieMegaModPack", textBox2.Text);
Directory.Move(source, destination);

Or in C# 6 you could use string interpolation:

string source = $@"{textBox2.Text}\@Jonzie Mega Mod Pack";
string destination = $@"{textBox2.Text}\@JonzieMegaModPack";
Directory.Move(source, destination);

I would recommend using Path.Combine instead though:

string source = Path.Combine(textBox2.Text, "@Jonzie Mega Mod Pack");
string destination = Path.Combine(textBox2.Text, "@JonzieMegaModPack");
Directory.Move(source, destination);

people

See more on this question at Stackoverflow