improve handling of file/directory modes

closes #105