writeandexecute: check for no directory in file argument

Only check whether the directory exist if the file argument
has a directory component. Prevents a error in that case.