- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to use the directory class in C#?
The Directory class in C# is used to manipulate the directory structure. It has methods to create, move, remove directories.
The following are some of the methods of the Directory class.
Sr.No. | Method & Description |
---|---|
1 | CreateDirectory(String) Creates all directories and subdirectories in the specified path |
2 | Delete(String) Deletes an empty directory |
3 | Exists(String) Whether the given path refers to an existing directory |
4 | GetCreationTime(String) Gets the creation date and time of a directory. |
5 | GetCurrentDirectory() Gets the current working directory |
6 | GetFiles(String) |
Let us learn about the usage of GetFiles() method in Directory class. It displays all the files in the specified directory.
Example
using System; using System.IO; class Program { static void Main() { // Get all files in the D directory string[] arr = Directory.GetFiles(@"D:\"); Console.WriteLine("Files:"); foreach (string n in arr) { Console.WriteLine(n); } } }
Advertisements