Should a directory path variable end with a trailing slash?

前端 未结 12 1981
暖寄归人
暖寄归人 2020-12-24 04:33

When defining a path to a directory as a variable or constant, should it end with a trailing slash? What is the convention?

pwd in Unix shows your curre

12条回答
  •  醉梦人生
    2020-12-24 05:03

    Yes, it should, as:

    Pathname + filename = fully qualified file location.

    SO the slash between the last directory and the filename needs to be either at the end of the pathname or the start of the filename. Prefixing filenames with a / means you need to take this into account if you just want to open a file (i.e if you assume that an unqualified filename is in the current working directory).

提交回复
热议问题