there is not a best way, just what you need to archive, take the file name as you mentioned is not the best practice, so you can use another parameter provided by SAP.
To evaluate the following attributes in the PI message header, set the corresponding indicators:
○ File Name (technical name: FileName)
○ Directory (technical name: Directory)
○ File Type (technical name: FileType)
○ File Encoding (technical name: FileEncoding)
do any of them are good for you?
Rdgs