Added more sanity checking for filenames and directory names.