Managing the Filesystem

Learn about managing the filesystem, exploring directory paths, and understanding filesystem differences between Windows, macOS, and Linux in a .NET context.

Our applications often need to perform input and output operations with files and directories in different environments. The System and System.IO namespaces contain classes for this purpose.

Handling cross-platform environments and filesystems

Let’s explore how to handle cross-platform environments and the differences between Windows and Linux or macOS. Paths are different for Windows, macOS, and Linux, so we will start by exploring how .NET handles this:

Step 1: Use the preferred code editor to create a new project, as defined in the following list:

  • Project template: Console App or console

  • Project file and folder: WorkingWithFileSystems

  • Workspace/solution file and folder: Chapter09

Step 2: In the project file, add an element to statically and globally import the System.Console class.

Step 3: Add a new class file named Program.Helpers.cs.

Step 4: In Program.Helpers.cs, add a partial Program class with a SectionTitle method, as shown in the following code:

Get hands-on with 1400+ tech skills courses.