fixed trailing slash problem with -d and added another case for the output

if there is a trailing slash in the argument of option -d, th script won't work, so I get rid of a trailing slash
added a 3rd case for the output to honor the -d option
Merge pull request #6 from tessus/master

fixed trailing slash problem with -d and added another case for the output