Home > Backend Development > C#.Net Tutorial > How to create a directory using C#?

How to create a directory using C#?

WBOY
Release: 2023-09-12 18:29:08
forward
640 people have browsed it

如何使用 C# 创建目录?

To create, move and delete directories in C#, the System.IO.Directory class has methods.

First, import the System.IO namespace.

Now, use the Director.CreateDirectory() method to create a directory in the specified path -

string myDir = @"D:\NEW";
if (!Directory.Exists(myDir)) {
   Directory.CreateDirectory(myDir);
}
Copy after login

Similarly, you can create a subdirectory −

string mysubdir = @"C:\NEW\my\";
Directory.CreateDirectory(mysubdir);
Copy after login

The above is the detailed content of How to create a directory 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