Should a directory path variable end with a trailing slash?

前端 未结 12 2033
暖寄归人
暖寄归人 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:09

    Whenever I store directory paths or return them from APIs, I try and stick with the convention of keeping a trailing slash. This avoids the whole 'is it a file or a directory' ambiguity.

    Addendum:
    This is not intended to be a substitute for using methods that can tolerate either a trailing slash or its absence. Even using this convention I still always use Path.Combine(...) and similar methods.

提交回复
热议问题