Home  >  Article  >  Backend Development  >  List directories and files using C#

List directories and files using C#

PHPz
PHPzforward
2023-08-22 22:29:021219browse

List directories and files using C#

In C#, the Directory class has many methods to operate on directories and subdirectories −

Serial number Methods and descriptions
1 CreateDirectory(String)

unless they already exist, Otherwise, all directories and subdirectories are created in the specified path.

2 CreateDirectoryDirectorySecurity(String)

Creates all directories in the specified path unless They already exist, with the specified Windows security applied.

3 Delete(String)

Deletes an empty directory from the specified path.

4 DeleteBoolean(String)

Delete the specified directory and delete it in the specified Delete any subdirectories and files in the directory.

5 EnumerateDirectories(String)

Returns the enumerable directory name in the specified path Lift collection.

6 EnumerateDirectories(String, String)

Returns the search in the specified path An enumerable collection of directory names that match the pattern.

To get the directory name, use the EnumerateDirectories method. We set the folder using DirectoryInfo class −

DirectoryInfo info = new DirectoryInfo(@"D:/new");

Now find the size −

long totalSize = info.EnumerateFiles().Sum(file => file.Length);

For directory use −

info.EnumerateDirectories()

The above is the detailed content of List directories and files using C#. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete