1) This part is recurring, so you should extract it to function.
2) Seems like much redundant work here. Why cannot you just search for similar prefix:
instead of:
```sub_paths_index = sub_paths.index(dir_stat[0].path)```
do:
```symlink_path.match("^" + dir_stat[0])```

If you want to get the next directory you can use dirname and basebname of
http://www.ruby-doc.org/core-2.1.1/File.html