If you don’t want to make a new file (or can’t because you ran out of inodes) you can run this query:
for i in `find . -type d `; do echo `ls -a $i | wc -l` $i; done | sort -n
as insider mentioned in another answer, using a solution with find will be much quicker since recursive ls is quite slow, check below for that solution! (credit where credit due!)