Home > Backend Development > C#.Net Tutorial > List directories and files using C#

List directories and files using C#

PHPz
Release: 2023-08-22 22:29:02
forward
1314 people have browsed it

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");
Copy after login

Now find the size −

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

For directory use −

info.EnumerateDirectories()
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template