//string path = "E://飞秋";//和下面效果一样
string path = "E:/飞秋";
string path1 = "E:/飞秋/2.txt";
if(!Directory.Exists(path))//判断文件夹是否存在
{
Directory.CreateDirectory(path);//创建不了文件
Console.WriteLine("创建成功");
}
else
{
Console.WriteLine("已经存在");
}
if(File.Exists(path1))//判断文件是否存在 .txt/.jpg等文件
{
Console.WriteLine("已经存在");
}
else
{
File.Create(path1);//创建不了文件夹
}
Directory和File的使用
最新推荐文章于 2025-03-05 20:41:46 发布