What is the naming standard for path components?

后端 未结 8 1548
广开言路
广开言路 2020-12-22 15:22

I keep getting myself in knots when I am manipulating paths and file names because I don’t follow a naming standard for path components.

Consider the following toy pr

8条回答
  •  执笔经年
    2020-12-22 16:21

    In C++, Boost.Filesystem has devised a nomenclature for the various parts of a path. See the path decomposition reference documentation for details, as well as this tutorial.

    Here's a summary based on the tutorial. For:

    • Windows path: c:\foo\bar\baa.txt
    • Unix path: /foo/bar/baa.txt

    you get:

    Part            Windows          Posix
    --------------  ---------------  ---------------
    Root name       c:               
    Root directory  \                /
    Root path       c:\              /
    Relative path   foo\bar\baa.txt  foo/bar/baa.txt
    Parent path     c:\foo\bar       /foo/bar
    Filename        baa.txt          baa.txt
    Stem            baa              baa
    Extension       .txt             .txt
    

    C++ standard ISO/IEC 14882:2017

    Moreover Boost.Filesystem terminology has been adopted by C++17 => See std::filesystem

    Function name     Meaning
    ----------------  -------------------------------
    root_name()       Root-name of the path
    root_directory()  Root directory of the path
    root_path()       Root path of the path
    relative_path()   Path relative to the root path
    parent_path()     Path of the parent path
    filename()        Path without base directory (basename)
    stem()            Filename without extension
    extension()       Component after last dot
    

提交回复
热议问题