Chapter 4Navigating the File System
When you’re developing your own command-line tools, you’ll often need to interact with the file system, navigate around the directory tree, or perform actions on files or directories. When you’re building a tool that’s supposed to work on multiple platforms, you have to pay special attention to how you manipulate paths and file names to ensure your tool works appropriately no matter where it’s run.
For example, Windows uses a backslash \ as a path separator, such as C:\WINDOWS\SYSTEM, while most variations of UNIX use the forward slash / instead, as in /usr/lib. In these scenarios, hard-coding paths and file names into the program can lead to errors or unexpected results.
To avoid these complications, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access