Refactor `filenameWithPath` into one function.