Manipulating Directories with the Directory Object

Manipulating directories (folders) is very similar to manipulating files. However, rather than using System.IO.File, you use System.IO.Directory. Notice that when you specify a directory path, double slashes are used instead of just one. If any of these method calls confuse you, see the previous section on System.IO.File for more detailed information. Following are the method calls:

  • System.IO.Directory.CreateDirectory()— Used to create a directory. You must pass it the name of the new folder as shown here (note that, as discussed in Hour 11, you must preference literal strings containing slashes with the @ character):

    System.IO.Directory.CreateDirectory(@"c:\my new directory");
    
  • System.IO.Directory.Exists()— ...

Get Sams Teach Yourself Microsoft® Visual C#™ .NET in 24 Hours now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.