Problem when recursing through directories
In my previous post I explained how you could build a class that uses recursion to scan through directories. On a similar article I wrote for CodeProject.com, I was brought to the attention of a possible issue that might occur when you do this.
It is possible to create an infinitely recursive directory tree on an NTFS drive. So if you don't provide a solution for this, you will create infinite loops in your application without being aware of the problem. An article explaining this issue can be found here. It's also where I found a solution, but you can simply try the following:
- Create a directory in the root of your C: drive, for example AAA.
- Right-click My Computer and select Manage.
- Click on Disk Management.
- In Disk Management, right-click the C drive and select "Change Drive Letter and Paths...".
- From the "Change Drive Letter and Paths for C:" dialog, click "Add"
- Where it says "Mount in the following empty NTFS folder", enter "C:\AAA". Click OK.
Congratulations, you just created an infinitely recursive directory. Just open op the Windows Explorer and select the AAA directory to see what happens. To solve this, you will need to check the attributes of the directory for the ReparsePoint attribute as in the following example:
if ((subDirectory.Attributes & FileAttributes.ReparsePoint) != 0)
// This directory has the FileAttributes.ReparsePoint attribute set
This fix is obviously available in the code that you can download in my post on How to: Scan directories using recursion.
Update June 4, 2006. I closed comments on this post.