Windows 7 infinite loop while using Robocopy
Short answer: If you're using Robocopy, simply using the /XJ switch will avoid this problem.
This recursive file structure is indeed caused by the implementation of junction points in the NTFS file structure by Microsoft. Essentially, some "folders" are not actual folders at all, but junction or reparse points, which essentially reroute a directory name to another directory. This is much like mapping a drive letter to a directory or another drive, and the Windows system is designed to handle this NTFS structure situation behind the scenes.
In Vista and 7, Microsoft decided to standardize some of the typical Windows settings for users, documents, etc., which had varied over time. To maintain backward compatibility, the old standards were also retained BUT WITH JUNCTIONS REPARSING THEM TO REDIRECT INQUIRIES INTO THE NEW ACTUAL DIRECTORIES. Most programs work right through these junctions without even noticing. For example, C:\Documents and Settings points to C:\Users. Even though the former directory does not actually exist, it APPEARS to have the files and directories under the latter, and a change in the contents of either directory will be reflected in the other, since they are in fact, a single directory.
The difficulty comes from certain Reparse Points which essentially redirect to a parent directory. This causes a recursive cascade for unwary programs or users who are unaware of the proper handling of the junctions (even though the junctions are designed to be transparent to software looking for either directory). The usual "subdirectory explosion" situation comes from the fact that the \Documents and Settings\$USER$\Application Data folder (consistent with XP convention) is a junction point in Vista to \Users\$USER$\AppData\Roaming, which in turn can contain the Application Data junction as a subdirectory...
Under normal Windows permissions, the junctions and their directories are inaccessible and hidden. If permissions are changed or programs working outside Windows are not prepared to encounter these junctions, duplication and recursion is destined to occur. For those using powerful low-level command interfaces such as Repair Console, it is best to check the capabilities and switches on the commands by using the /? help switch (for example, Robocopy /?, xcopy /?, rd /?, etc.). If you are not sure what you are doing, be sure to backup ahead of time with a reliable Windows program, with proper use of Restore Points.
Another useful discussion is here: http://www.vistax64.com/vista-general/58035-nested-application-data-directory.html
I had the same thing happen. I used the /purge function in robocopy to clear up the issue after being unable to delete through windows explorer. I created a blank folder called purge and then ran the following to clear the folders:
ROBOCOPY source C:\PURGE\ dest BACKUP PATH\APPLICATION DATA /PURGE
Since the source folder is empty robocopy will delete everything in the destination path regardless of filename length.
This really solve the problem you have. The correct syntax is:
robocopy c:\purge d:\users /purge
where "d:\users" is the infinite loop path
Also make sure to create a blank folder named "purge" in c:\ as mentioned above
Run the robocopy command a few times until it delete all the copied folders. It works for me.