Alex
Alex

Reputation: 68044

How to get realpath for virtual paths?

if path is ../b and current directory is /var/www/a/c, then realpath would be /var/www/a/b

but if b doesn't exist, realpath() returns false.

Is it possible to get the same path even if directory doesn't exist yet?

Upvotes: 3

Views: 1054

Answers (1)

Joachim Isaksson
Joachim Isaksson

Reputation: 180927

It's not available as a pre-defined function format like realpath(), just because it's impossible to do in a reliable way.

As an example, on MacOS, doing ls /etc/.., you'd think that you'd get a directory listing of /. The thing is though that /etc is a soft link to /private/etc, so doing ls /etc/.. gives you a listing of /private.

This could not be calculated in advance if the link did not yet exist, which is why there is no function that can solve it in the general sense without all files/directories already existing.

In other words, you'd most likely have to write your own function to solve your specific problem.

Upvotes: 5

Related Questions