質問

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?

役に立ちましたか?

解決

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top