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:

  • To create a directory, call the CreateDirectory() method of System.IO.Directory, passing the name of the new folder, like this: (Note: As discussed in Hour 12, you must preference literal strings containing slashes with the @ character.)

    System.IO.Directory.CreateDirectory(@"c:\my new directory");
    
  • To determine whether ...

Get Sams Teach Yourself C#™ 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.