Managing the filesystem
Your applications will often need to perform input and output with files and directories. The System.IO
namespace contains classes for this purpose.
Managing directories
In Visual Studio 2017, press Ctrl + Shift + N or choose File | New | Project....
In the New Project dialog, in the Installed | Templates list, select .NET Core. In the center list, select Console App (.NET Core), type Name as Ch10_FileSystem
, change the location to C:\Code
, type the solution name as Chapter10
, and then click on OK.
In Visual Studio Code, in the Integrated Terminal, make a new directory named Chapter10
, and a subdirectory named Ch10_FileSystem
. Open the folder and enter the command dotnet new console
.
At the top of the Program.cs
file, add the following import statements. Note that we will statically import the Directory
type to simplify our code:
using static System.Console; using System.IO; using static System.IO.Directory;
In the Main
method, write the following...