edited script to take directories of files as input