Made the script usable for filenames/dirs with spaces in them

usable in scenarios when directory/filenames have spaces.

Also removed some trailing spaces on a couple of lines

This needs more testing before merging. It works in my situation,
where I have filenames with spaces, but should be tested some more.