In this post, I'll discuss how to handle file paths in Pascal in a cross-platform manner. I have newly written the following functions, because I often encountered problems with the Delphi and FreePascal own appropriate functions in terms of cross-platform difficulties. So I reinvented the wheel out of necessity, but for the cross-platform special case, where each build variant must also support the each other path convention. Specifically, I'll focus on converting between relative and absolute paths, expanding relative paths, including handling UNC paths and so on. I'll also provide an in-depth analysis of each function, detailing the logic and edge cases they handle. So, let's get started.
IsPathSeparator
The IsPathSeparator
function checks if a character is a path separator. It considers '/' and '\' as path separators. This fundamental function forms the basis for parsing the paths in the following functions, and is crucial for ensuring cross-platform compatibility. It's implemented as a function rather … (read more)