I haven't tested this, but the idea is that, since the paths are all absolute, a change in level means a difference in the number of path seperators. (You might want to use a more portable form of the seperator than a literal "/".)