-2

I am trying to execute 'move' command, how you would in the command prompt, but it fails using Process.Start(). I understand move seems to be some integrated part of cmd and not an isolated executable, is there any way to trigger it using Process anyway ? I need to move some special location folder and trying to use elevated process instead of Directory.Move.

frno
  • 1,064
  • 11
  • 24

1 Answers1

1

That should work. The arguments should start with '/C' otherwise won't work.

var process = new Process
    {
         StartInfo = new ProcessStartInfo
            {
                FileName = "cmd.exe",
                Arguments = @"/C move ""test.txt"" ""test/test.txt""",
                UseShellExecute = false
            }
    };

process.Start();
crankedrelic
  • 463
  • 1
  • 5
  • 14
  • 1
    (Just as a note: the default for `UseShellExecute` changed from `true` to `false` with the introduction of .NET Core. Annoyingly, therefore, portable code which runs on both Framework and Core needs to always explicitly set it, as this answer does) – canton7 Apr 29 '21 at 15:18