Refactored function for generating file path.