How do you check whether a path is absolute or relative, using C on Linux?
如何在Linux上使用C来检查路径是绝对路径还是相对路径?
4 个解决方案
#1
17
Absolute paths tend to start with the /
character. Anything else is pretty much relative from the working directory.
绝对路径往往以/字符开头。其他任何东西都与工作目录非常相关。
Even directories with ..
sequences in them are considered absolute if they start with /
since they end up at the same position in the file system (unless you change links and things but that's beyond the discussion of absolute and relative).
即使带有..序列的目录,如果它们以/开头,也会被认为是绝对的,因为它们最终位于文件系统中的相同位置(除非您更改链接和事物,但这超出了绝对和相对的讨论范围)。
#2
9
It's absolute if it begins with a /
, otherwise relative.
如果它以/开头,则是绝对的,否则相对。
#3
4
Check if the path starts with /
or not. if path starts with /
you can assume it is absolute.
检查路径是否以/或不是。如果路径以/开头,你可以认为它是绝对的。
#4
3
Check if the path starts with / or not. if path starts with / you can assume it is absolute otherwise it's relative means it will update from pwd(present working directory) But in Absolute case path will update relative to root directory
检查路径是否以/或不是。如果路径以/开头,你可以认为它是绝对的,否则它的相对意味着它将从pwd(当前工作目录)更新但是在绝对情况下路径将相对于根目录更新
#1
17
Absolute paths tend to start with the /
character. Anything else is pretty much relative from the working directory.
绝对路径往往以/字符开头。其他任何东西都与工作目录非常相关。
Even directories with ..
sequences in them are considered absolute if they start with /
since they end up at the same position in the file system (unless you change links and things but that's beyond the discussion of absolute and relative).
即使带有..序列的目录,如果它们以/开头,也会被认为是绝对的,因为它们最终位于文件系统中的相同位置(除非您更改链接和事物,但这超出了绝对和相对的讨论范围)。
#2
9
It's absolute if it begins with a /
, otherwise relative.
如果它以/开头,则是绝对的,否则相对。
#3
4
Check if the path starts with /
or not. if path starts with /
you can assume it is absolute.
检查路径是否以/或不是。如果路径以/开头,你可以认为它是绝对的。
#4
3
Check if the path starts with / or not. if path starts with / you can assume it is absolute otherwise it's relative means it will update from pwd(present working directory) But in Absolute case path will update relative to root directory
检查路径是否以/或不是。如果路径以/开头,你可以认为它是绝对的,否则它的相对意味着它将从pwd(当前工作目录)更新但是在绝对情况下路径将相对于根目录更新