Home  >  Article  >  Backend Development  >  How to create a directory using C#?

How to create a directory using C#?

WBOY
WBOYforward
2023-09-12 18:29:08588browse

如何使用 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);
}

Similarly, you can create a subdirectory −

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

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!

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