What is the naming standard for path components?

后端 未结 8 1545
广开言路
广开言路 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:17

    The Pathlib standard library in Python has a simple naming convention for path components:

    A. /x/y/z/foo.tar.gz > stem.

    B. /x/y/z/foo.tar.gz > name.

    C. /x/y/z/foo.tar.gz (excluding dot) > N/A.

    D. /x/y/z/foo.tar.gz (including dot) > suffix.

    E. /x/y/z/foo.tar.gz > grand parent path.

    F. /x/y/z/foo.tar.gz > relative path to grand parent path.

    G. /x/y/z/foo.tar.gz > parent name.

    H. /x/y/z/foo.tar.gz > parent path.

    I. /x/y/z/foo.tar.gz > path.

    0 讨论(0)
  • 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:               <empty>
    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
    
    0 讨论(0)
提交回复
热议问题