Using pathlib to work with filenames
Most operating systems use a hierarchical path to identify a file. Here's an example filename:
/Users/slott/Documents/Writing/Python Cookbook/codeThis full pathname has the following elements:
- The leading
/means the name is absolute. It starts from the root of the filesystem. In Windows, there can be an extra letter in front of the name, such asC:, to distinguish the filesystems on each individual storage device. Linux and Mac OS X treat all of the devices as a single, large filesystem. - The names such as
Users,slott,Documents,Writing,Python Cookbook, andcoderepresent the directories (or folders) of the filesystem. There must be a top-levelUsersdirectory. It must contain theslottsubdirectory. This is true for each name in the path.
- In Windows, the OS uses
\to separate items on the path. Python uses/. Python's standard/is converted to the Windows path separator character gracefully; we can generally ignore the Windows\.
There is no way to tell...