How would you go about resolving a relative path? What I am looking for is a function similar to php's realpath. The function just needs to remove all ../ ./ so that the input string can be safely used with other strings.
The general way is to use the File class getCanonicalPath() method.
It's specifically documented to remove (resolve) the ../
and ./
that you're looking for.
Extracts from the docs:
This method first converts this pathname to absolute form if necessary [...] and then maps it to its unique form in a system-dependent way. This typically involves removing redundant names such as "." and ".." from the pathname, resolving symbolic links (on UNIX platforms), and converting drive letters to a standard case (on Microsoft Windows platforms).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With