Following Components of a Filesystem Path
Resolving a path usually walks directory entries component by component from an appropriate base.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 4
- Reading time
- 1 min
In this article4 chapters
Trace a short path
Resolving reports/weekly.txt first finds reports as a directory, then looks up weekly.txt inside it. A missing first component prevents the second lookup. Current working directory can supply the base for relative paths.
Check emitted diagnostics
A requester can benefit from knowing that a directory is unavailable separately from a missing final file. See path construction for how those components may have been formed.[1]
Follow each component in the actual starting location
A path like docs/../data/readings.txt ordinarily begins at a working directory and resolves each component. A symbolic link encountered along the way can change physical traversal, so simplifying a path string may not preserve the object it resolves to. See filesystem links.
Start at /project
Resolve each directory entry in order
Follow links according to platform semantics
Open the final object only if every required step succeeds
Report the first step that fails
A name can fail because an intermediate entry is missing or is a regular file when a directory is needed. Operating systems distinguish some of these outcomes. Test each against an isolated fixture.