fixed error with checking for directory instead of file