1

Suppose I have a folder under partition D that is D:\folder\link_folder which is a directory symbolic link whose target is E:\real_folder, i.e. it was created by:

mklink /d D:\folder\link_folder E:\real_folder

Now I need to move D:\folder to F:\ by the Explorer UI like cut/paste. But I found that now there is a full copy of E:\real_folder under F:\folder\link_folder which is not a link anymore.

Is there a way to just create F:\folder\link_folder as a link to E:\real_folder during the folder move process? There is a lot of such links under D:\folder.

  • How did you try, with Explorer or with Some Commander? Perhaps you could try doing it from WSL: unix products do know the concept of symlinks. – Lorinczy Zsigmond Aug 27 '19 at 4:05
  • Why can’t you delete the symbolic link, move the files, then recreate the symbolic link? – Ramhound Aug 27 '19 at 4:31
  • @Ramhound There are a lot of symbolic links. Want a command/flag that can just move the symbolic link which is as expected by the user. – jw_ Aug 27 '19 at 5:35
1

You can use robocopy to move folders that contain directory symbolic links by using the /move /SL and /e parameters. Following your example, you could then use the command as follows:

robocopy D:\folder F:\folder /move /e /SL

/move will move the target instead of copy.

/e will copy (move) all sub-directories including empty ones.

/SL will copy (move) the symbolic link instead of following it.

note: elevated command prompt is required for moving symbolic links in windows 10.

note: For symbolic links created using mklink /d.

References: Microsoft Docs robocopy contains syntax and details on robocopy, examples can be found at Technet robocopy examples. Related forum post on copying directory symlinks in Windows 7.

  • The strange thing is that if I don't do this with a administrator command window it will say like "client doesn't have the privilege, waiting for 30 seconds", even I'm testing your solution with newly created simple folders. I don't want to use administrator command windows since this may somehow polute the moved files's ownerships etc. – jw_ Aug 31 '19 at 7:50
  • Maybe you can check this question too: superuser.com/questions/1476047/… – jw_ Aug 31 '19 at 7:53
  • You can use the/copy:parameter to specify what file properties to copy (move). By default, it uses/copy:DAT(Data, Attributes, Timestamp), you can add the O flag to copy and thus preserve the ownership, so it would be/copy:DATO. The Microsoft Docs Robocopy page has description for the various flags for/copy:and the corresponding file properties in case there are other access controls you need to to move with the file. – Gen Test Sep 1 '19 at 10:16
  • What about why it reports the previlege error even I test the command on some newly created folders? – jw_ Sep 2 '19 at 2:55
  • My apologies, it appears that post windows 10 creator's update, enabling developer mode first will then allow moving/creating symlinks without elevated privileges. Otherwise you will still need elevated privileges. I'll update the answer. – Gen Test Sep 2 '19 at 3:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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