I'm having difficulty using Robocopy.

There are two things to which I want to do with Robocopy and I'm unsure whether it is possible. First create a symbolic link which links the source to the new target and second exclude a sub-folder from the source from being included in the symbolic link ?

This is the command to which I attempted; it works but not in the way as described I had hoped ?

"C:\<sourceFolderPath>" "C:\<folderA>" /sl /xd

Recommended Answers

All 23 Replies

" exclude a sub-folder from the source from being included in the symbolic link ? "

That's going to be very tricky. You would have to tweak ownership and permissions just so (sorry no, I bow out on that) and disallow the user access to that subfolder.

This is so tricky that I'm going to write it's just too much to setup and maintain unless you are fluent with both NTFS and your server's permissions.

As I understand it, the /SL switch says that rather than treating the symbolic link folder as a real folder (and doing a deep copy), just create a symbolic link in the target folder with the same name as the original symbolic link and pointing to the same target.

If that is the case then it makes no sense to try to exclude a subfolder of the symbolic link because it will not be copied anyway. And if you want to create the symbolic link in the target folder then by definition the actual subfolders of the new symlink must be the same subfolders as the original symlink because they both point to the same thing.

In OOP terms, you have two pointers pointing to the same object. By definition the target object is equal to itself.

@Reverend Jim - Arn't symbolic link targets just duplicates of the source ? Therefore the /SL switch should accomblish what I want. With symbolic links the source is copied to the new target name and if any sub-folders exist those too get mirrored so to speak; that is where I want to exclude a sub-folder.

It sound as though I mis-understood and it's impossible ?

A symbolic link is just a pointer to a folder. It is typically used for compatibility reasons. They may also be called "junctions". For example, if you do the following in a command shell in Windows 10

c:
dir /a:d

you might see

2016-04-18  18:48    <DIR>          $Recycle.Bin
2017-03-11  11:08    <DIR>          AMD
2016-04-01  11:28    <DIR>          Apps
2016-10-18  15:41    <DIR>          boot
2017-03-25  11:36    <DIR>          Config.Msi
2016-04-01  13:23    <DIR>          Dell
2016-04-15  13:43    <JUNCTION>     Documents and Settings [C:\Users]
2016-04-01  11:43    <DIR>          Drivers
2017-03-25  15:54    <DIR>          Intel
2017-01-24  19:39    <DIR>          PerfLogs
2017-02-23  20:24    <DIR>          Program Files
2017-03-18  08:15    <DIR>          Program Files (x86)
2017-03-25  11:36    <DIR>          ProgramData
2016-10-05  15:36    <DIR>          Recovery
2017-03-27  09:08    <DIR>          System Volume Information
2016-06-17  08:25    <DIR>          TMRescueDisk
2016-10-05  15:41    <DIR>          Users
2017-03-25  15:54    <DIR>          Windows

Note the folder listed with <JUNCTION>. The folder name, Documents and Settings. That folder doesn't really exist. It is just a symlink. If you cd into ityou will actually end up in C:\Users. That is because older versions of Windows stored the user profiles in Documents and Settings and any apps that look for profiles in that folder will actually get redirected to the correct folder.

It's sort of (and not sort of) like a shortcut on your desktop. The shortcut is a link to something (an app, folder, file, internet site, etc). You can copy the shortcut to another location. Doing so does not copy the app (or foilder, file...). It just copies the reference to it and running the copied shortcut has the same effect as running the original shortcut.

Therefore Robocopy doesn't do what I want to do, which is create a symbolic link between two folders but exclude a sub-folder from the source folder as so I though when searching for a more powerful alternative to symbolic links ?

@Siberian, if I remember your prior conversations you want to sync folders and now want to exclude a subfolder from the sync.

Symbolic links have little to nothing to do with what you want to achieve and can send us into the void.

So if I forget symbolic links altogether and restate the goal as:
"Sync two folders EXCEPT for a specific subfolder" then you might find a way.

https://www.google.com/search?q=robocopy+all+but+one+folder finds it does have a /XD (exclude directory) and that may be it.

@rproffitt - The previous conversation regarding syncing folders and this new problem with regards to syncing folders are not the same :)

With this new problem, symbolic links would work; except, symbolic links doesn't allow me to exclude sub-directions from the symbolic link creation. That is where after searching I was surprised, or so I think that Robocopy can complete this task.

I'm aware that is /xd flag can exclude a directory / sub-director (folder) as I posted here;

"C:\<sourceFolderPath>" "C:\<folderA>" /sl /xd

The above command did work within Robocopy, not in the way I had hoped. Which was to to make the symbolic link and exclude a sub-folder from the symbolic link folder when creating the symbolic link.

Reverend Jim has shed some light on this issue, but no workable conclusion has been drawn which is my goal :)

robocopy /sl C:\ResourceA C:\ResourceB\Sync\Acme /xd *"DocumentsAB"

The above command worked, and created the Acme sub-folder; although it only copied the main contents from the folder ResourceA and excluded all the sub-folders from the folder ResourceA ?

Second, when copying a file to the folder ResourceA it doesn't get copied to the Acme sub-directory as normally a symbolic link would work ?

"as normally a symbolic link would work ? "
Sorry no, I have never seen a symbolic link do what you asked so far.

As to robocopy not picking up all folders I think more inspection of permissions on the source folder is needed as well as checking your robocopy syntax. I think you are close to getting it to sync.

The above command did work within Robocopy, not in the way I had hoped.

If it doesn't do what you want then it isn't working (the way you want). Technically, any command that doesn't generate an error can be considered to "work" in that it does exactly what it is told to do even if what it is told to do isn't what you want it to do. Confused yet? So am I because I am no longer sure what you are trying to do.

@Reverend Jim, I understand what you're saying, although not confused. :)

@rproffitt - What am I doing wrong with regards to the command as to why it won't sync, sync as in symbolic link being created between source and target and exclude a sub-folder from syncing from the source ? <g>

Are you trying to exclude a subfolder of the symlink folder? If so, you can't do that. If I'm still mistaken then can you possibly explain what you want by showing us the folder structure of your source, and what you want the target to look like? Please label physical folders with <DIR> and symlink folders with <JUNCTION> as would be displayed in a command shell dir listing.

Here is an example; here are two folders, one named Acme; the other Tower.

Click Here

I want to create a symbolic link using Robocopy from the folder Acme to the folder Tower. Maybe I shouldn't have included any proxy folder names for Tower in the image, I hope it doesn't confuse anyone.

The folder within the Acme file structure with the red circle around is, in the example; the only folder to which I don't want included in the symbolic link. Therefore any files created, copied or edited to this sub-folder will not effect the target folder as it wasn't included.

That is exactly what my goal is.

Here's where you lose me. "I want to create a symbolic link using Robocopy"

Either you want to sync or you want to create a symbolic link. Mixing terminology is where I have to write it's time to get that clear first.

If you want to sync and rename folders along the way, you'll have to add more lines to your script to do this. That is, if you have 4 folders to sync, 4 lines in your script.

You don't use robocopy to create a symlink. You can use the junction command to do that.

D:\>junction /?

Junction v1.02 - Win2K junction creator and reparse point viewer
Copyright (C) 2000 Mark Russinovich
Systems Internals - http://www.sysinternals.com

The first usage is for displaying reparse point information, and the
second usage is for creating or deleting a NTFS junction point:

usage: junction [-s] <file or directory>
       -s     Recurse subdirectories

usage: junction [-d] <junction directory> [<junction target>]
       -d     Delete the specified junction
       example: junction d:\link c:\winnt

I want to create a symbolic link, the importance is; I do not want to include a sub-folder within the source that would be a junction when creating the symbolic link. I don't want to sync, since a symbolic link does the Job, it's only problem is it includes all the sub-folders from the source, and I want to exclude a sub-folder.

This page has all the flags listed that go along with Robocopy.

There is an /XD & /SL flag; it would appear that the /SL flag does almost if not the same as a symbolic link and when I tried it, specifically (2) files were copied from the source to the target, why only (2) and not all (3) which were in the folder, and excluding the sub-folders I don't understand ?

What you are asking can not be done because it doesn't make sense. It's like asking someone to draw a square circle or an equilateral triangle with a right angle. If you have two pointers that both point to the same thing then the things must be equal because they are the same thing. If you want the two things to be different then they have to be different things and you can't use pointers (symlinks).

What is the purpose of the /XD & /SL flag ?

/xd is used to exclude subfolders and only applies when copying actual folders.
/sl is used to replicate symlinks that are in the source tree to the target tree (rather than copy the folders that the symlinks point to).

/sl is used to replicate symlinks; therefore I have to create a symbolic link first ?

Dont you think its high time to replace robocopy with some other software. I seriously don't like to remember all these commands with parameters. Who does that man! Plus it hangs at times. So now I have stopped using it, and now I am using GS Richcopy 360. It has easy to use GUI and way more features than robo. Consider replacing the old software. Thanks!

@Catherine. Great idea but what if I want to automate this? Does GS Richcopy 360 offer a command line version?

commented: Well, if you want a command line option you can always use robocopy ^_^ +14

SyncBack Free allows you to schedule backups.

commented: Thanks RevJ. When I use the command line (all too often) it's all I need. Some are put off by having to tell the computer what to do. +12
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.