This looks wrong - should it not return null or empty string here? `"dir"` is not the filename.