function for generating menus from a given directory