Creating a directory

Using the DirectoryInfo class, we can also create new directories in the filesystem. The following code illustrates how we create a new directory in the system:

Directory.CreateDirectory("C:\UCN Code Base\Programming-in-C-Exam-70-483-MCSD-Guide\Book70483Samples\Chapter 20"); 

If the preceding code is executed, it will create a subdirectory called Chapter 20 in the root folder. 

In the preceding code, we are passing an absolute path to create the directory. However, if we need to create a subdirectory in a particular directory, we can just execute the following code:

DirectoryInfo subDirectory = parentDirectory.CreateSubdirectory("NameChildDirectory");

In the preceding code, parentDirectory is the parent directory in which we want to create the subdirectory. NameChildDirectory is the name that we want to give to the child directory.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.223.171.162