Managing the filesystem
Your applications will often need to perform input and output 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.
- Create a new console application named
WorkingWithFileSystems
in a folder namedChapter09
. - Save the workspace as
Chapter09
and addWorkingWithFileSystems
to it. - Import the
System.IO
namespace, and statically import theSystem.Console
,System.IO.Directory
,System.Environment
, andSystem.IO.Path
types, as shown in the following code:using System.IO; // types for managing the filesystem using static System.Console; using static System.IO.Directory; using static System.IO.Path; using static System.Environment;
Paths are different for Windows, macOS, and Linux, so we will start by exploring...