Fixed wrong statement

Parameter -d  return true value if path exists and is a directory. So for file we should use -f.
[ -f /some/file ] returns true when file exists, so statement branches should be switched.