Udostępnij za pośrednictwem


Using Robocopy to Move Files and Folders

I use Robocopy a lot, and it's been in my Toolbox for so long that I hardly remember using anything else. I was glad to see that it is now included out-of-the-box (starting with Vista), because I typically use it instead of Windows Explorer to move or copy files, since I prefer the way it reports the progress of the lengthy file operations.

Note that when you specify the "/S /MOV" or "/E /MOV" options (to recursively move files from one location to another), it may leave behind a bunch of empty folders depending on the contents of the source and what you specify to move.

Over a year ago I went through the rather painful effort of organizing my thousands of digital photos. During the process of moving thousands of files around to various folders, I ended up with lots of empty folders in my source folder structure.

As I discovered earlier this week, you can specify the /MOVE option (instead of /MOV) to move both the files and directories, and delete them from the source after they are copied.

Perhaps now my blog post from earlier this week about deleting empty folders makes a little more sense ;-)

Sometimes I'm amazed at what I learn while blogging. I had just been in such the habit of using the /MOV option that I never gave it any thought (that is, until this week).

Comments

  • Anonymous
    August 05, 2010
    i download robocopy and ran it. running well.

  • Anonymous
    January 16, 2011
    i used it to move c:users to d:users, but what is the command to move your program files folder? I used: robocopy c:program files d:program files /mir /xj. But keep getting the error: bad command d:program. seems the 2 named folder is messing it up?

  • Anonymous
    January 16, 2011
    The comment has been removed

  • Anonymous
    April 04, 2011
    Hi Jeremy, I am using Robocopy from C#, but when trying to download a file with size > 300 MB, file is copied but Robocopy exe is not coming out of processing/hung..here I am sending the piece of code: string loc_robocopy = @"C:WindowsSystem32Robocopy.exe"; string arg_robocopy = srcFolder + "  " + AppSettings["OutputFilePath"] + "  " + outputFile;                         System.Diagnostics.Process proc_robocopy = new System.Diagnostics.Process();                         try                         {                             proc_robocopy.StartInfo.Arguments = arg_robocopy;                             proc_robocopy.StartInfo.FileName = loc_robocopy;                             proc_robocopy.StartInfo.CreateNoWindow = false;                             proc_robocopy.StartInfo.UseShellExecute = false;                             proc_robocopy.StartInfo.RedirectStandardError = true;                             proc_robocopy.Start();                             proc_robocopy.WaitForExit(600000);                             string exitCodestr = "";                             exitCodestr = proc_robocopy.ExitCode.ToString();                         }                         catch (Exception ex)                         {                            Console.WriteLine( ex.Message);                         } Can you please tell me whether I need to mention any other parameter ?