C# DirectoryInfo Tutorial with Programming Examples and Codes

active-directory
In this chapter you will learn:

  • What is DirectoryInfo class in C#?
  • How to get Directory details using DirectoryInfo class?
  • Programming Examples and codes.

What is DirectoryInfo class in C#?

DirectoryInfo class allows you to work with directory and its make directory manipulation as create, delete, info etc easy. It exposes instance methods for creating, moving, enumerating through directories and subdirectories.

Notes

  1. DirectoryInfo class is used for typical operations such as copying, moving, creating or deleting directories.
  2. This class cannot be inherited.
  3. By default full read/write access to new directories is granted to all users.

How do I get Directory Details?

The given example will demonstrate well DirectoryInfo class. This program check for a directory “D:\csharp” and If directory will be there it will show information of directory else it will create a new directory D:\csharp

  • Programming Examples and Codes

    Output

    D:\csharp1Directory is created successfully
    If you want to delete this directory press small y. Press any key to exit.

    _

    Summary

    In this chapter you learned DirectoryInfo class and their programming uses. The next chapter is FileInfo class which will teaches you how to use it in c# programming.


    Leave a Reply

    Your email address will not be published. Required fields are marked *