Managing the filesystem
Your applications will 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, Linux, and macOS. Paths are different for Windows, macOS, and Linux, so we will start by exploring how .NET handles this:
- Use your preferred code editor to create a new project, as defined in the following list:
- Project template: Console App /
console
- Project file and folder:
WorkingWithFileSystems
- Solution file and folder:
Chapter09
- Project template: Console App /
- In the project file, add a package reference for
Spectre.Console
, and then add elements to import the following classes statically and globally:System.Console
,System.IO.Directory
,System.IO.Path
, andSystem.Environment
, as shown in the following markup:
<ItemGroup>
<PackageReference...