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 like 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:
- Use your preferred code editor to create a new solution/workspace named
Chapter09
. - Add a console app project, as defined in the following list:
- Project template: Console Application/
console
- Workspace/solution file and folder:
Chapter09
- Project file and folder:
WorkingWithFileSystems
- Project template: Console Application/
- In
Program.cs
, add statements to statically import theSystem.Console
,System.IO.Directory
,System.Environment
, andSystem.IO.Path
types...