3
 private void bt_edit_folder_name_Click(object sender, EventArgs e)
    {
        Directory.Move("\\\\192.168.1.244\old_name", "\\\\192.168.1.244\new_name");
        MessageBox.Show("Done");
    }

I've used the same path to change the FILE name and it works fine BUT I can not use the same path to change the folder name. it show this debug error:

The specified path is invalid
1
  • 3
    Written like that, your strings would contain a newline and the nonexistent escape character \o - what is your actual code? Commented Dec 14, 2013 at 11:18

4 Answers 4

3

you can use verbatim string to solve your issue

 Directory.Move(@"\\192.168.1.244\old_name", @"\\192.168.1.244\new_name");
1
  • Thank you very much it works fine now with both files and folders (directories), I've spent many hours trying to solve this issue. :)
    – CrownFord
    Commented Dec 14, 2013 at 11:30
1

if you have trouble to move directories using c#, then you can try to do with cmd commands using process it should work,

    String command="xcopy "+srcPath+" "+destPath+" /i /q /s /y";
    Process p = Process.Start(new ProcessStartInfo()  {
        FileName = "cmd",
        Arguments = "/c \"" + command + "\"",
        RedirectStandardError = true,
        RedirectStandardInput = true,
        RedirectStandardOutput = true,
        UseShellExecute = false
    });
    p.Start();
    string output = p.StandardOutput.ReadToEnd();//read error & feedback messages
    string error = p.StandardError.ReadToEnd();
    p.WaitForExit();
0

The only way you could be getting this exception is if you don't meet the naming conventions. The documentation states:

sourceDirName or destDirName is a zero-length string, contains only white space, or contains one or more invalid characters as defined by InvalidPathChars.

So, in other words, the destDirName is invalid.

0

try this

var dir = new DirectoryInfo(@"\\192.168.1.244\old_name");
dir.MoveTo(@"\\192.168.1.244\tmpName");
dir.MoveTo(@"\\192.168.1.244\new_name");

Not the answer you're looking for? Browse other questions tagged or ask your own question.