Messy code for obtaining info about files in a directory