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
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
.
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:
c:\foo\bar\baa.txt
/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
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