Search code examples
cmdmoverobocopy

Robocopy in CMD Doesn't Copy the Parent Directory


For example

  • I use "robocopy /move /s /e"
  • to cut C:/folder1/folder2/folder3/
  • and paste into D:/library/
  • but I only get D:/library/folder4/folder5/folde6

Where did folder3 go?

edit 1: it's supposed that within folder3 pre-exist folder4, folder5 and folder6.

edit 2: Here's what I'm trying... robocopy /move /s /e "%1" "D:\library"

edit 3: Registry code

edit 4: Expected context menu in W10.


Solution

  • The basic syntax of the Robocopy command is

    robocopy source-directory destination-directory [pattern...] [options]

    If no pattern is given, the default pattern is *.*.

    The querent probably said something like

    robocopy C:\folder1\folder2\folder3 D:\library  /move /s /e
             ^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^  ^^^^^^^^^^^
                 source directory       destination    options
    

    This command tells RoboCopy to move all (the default pattern in *.*) the files and directories it finds in C:\folder1\folder2\folder3 to D:\library. Robocopy did that as expected.

    To move the directory folder3 from C:\folder1\folder2 to D:\library, the command is

    robocopy  C:\folder1\folder2\folder3  D:\library\folder3   /move /e
              ^^^^^^^^^^^^^^^^^^^^^^^^^^  ^^^^^^^^^^^^^^^^^^   ^^^^^^^^
                    source directory         destination        options
    

    Robocopy will create the destination directory D:\library\folder3 if needed. Note that the option /e implies /s.

    Since the question appears to refer to how to do it in batch file, and assuming that %1 does not end in a backslash, I suggest to replace robocopy /move /s /e "%1" "D:\library" with

    robocopy /move /s /e "%1" "D:\library\%~nx1"