using System;
using System.IO;
class Program
{
static void Main()
{
// 定义文件夹路径
string folderPath = @"C:\ExampleFolder";
// 判断文件夹是否存在,如果不存在则创建
if (!Directory.Exists(folderPath))
{
Directory.CreateDirectory(folderPath);
Console.WriteLine("文件夹已创建: " + folderPath);
}
else
{
Console.WriteLine("文件夹已存在: " + folderPath);
}
}
}
System
和 System.IO
命名空间,System.IO
提供了对文件和目录进行操作的功能。string folderPath
变量定义要检查或创建的文件夹路径。Directory.Exists(folderPath)
方法来检查指定路径的文件夹是否存在。Directory.CreateDirectory(folderPath)
方法创建该文件夹。这样可以确保在程序运行时,指定的文件夹存在。如果不存在,则会自动创建。
上一篇:c# const
下一篇:c# async await
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站