Use a better sorting algorithm

Now, instead of blindly importing directory structure, we must manually
import subdirectories everywhere.  This is painful, but if we do it in
the appropriate order (namely, we count how many levels are left, and
sort in reverse order by that), then, hopefully, we will never end up
importing a directory when we mean to import a file.  Hopefully.