Changed code to handle spaces in filenames.