Check the real directory path against used directories, and fix the counter comparison

Reported and tested by:	antoine