I need to build a Windows (only) file path from a combination of a UNC path passed to my script as a parameter, an API call, and a calculated date.
I'm having a horrible time of it, mostly caused by Windows' use of a backslash character to delimit file paths. I've read that the "pathlib" module should be able to sort this mess out, BUT it apparently doesn't support concatenation when building out file paths.
The UNC path is being passed out to the script as a dictionary from another application (PRTG Network Monitor:
{"fileshare": "//server02/logs/"}
I read that in and then need to append a hostname derived from an API call:
logPath = Path(params["fileshare"] + "/" + apiHostname + "/")
I then calculate a date which needs to be appended to the logpath, along with a delimiter "-" and a filename suffix:
filePath = Path(logPath, + apiHostname + "-", + past_day + ".log" )
The problem arises during the concatenation:
{"text": "Python Script execution error: unsupported operand type(s) for +: 'WindowsPath' and 'str'", "error": 1}}
Can someone please explain how I can build a path so that the calculated filename, which should look like this:
\\server02\logs\log01.rhmgmt.lan\log01.rhmgmt.lan-2021-07-28.log
Can be opened for processing?