Improved directory listings.

Added functions to count the number of items in a listing (MOB-104),
and when sorting a list, directory appear before files (MOB-131).