using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace addDirectory
{
class Program
{
static void Main(string[] args)
{
string activeDir = @"D:\myDir";
if (Directory.Exists(activeDir))//如果不存在就创建file文件夹{MessageBox.Show("存在文件夹");
//Directory.Delete(aaaa, false);//如果文件夹中有文件或目录,此处会报错
{
// MessageBox.Show("已存在同名文件夹 是否重新创建?(Y or N)");
Console.WriteLine("已存在同名文件夹 是否重新创建?(Y or N)");
string scan = Console.ReadLine();
if (scan == "Y" || scan == "y")
Directory.Delete(activeDir, true);
}//true代表删除文件夹及其里面的子目录和文件}
else
{
Console.WriteLine("不存在此文件夹 正在创建");
}
System.IO.Directory.CreateDirectory(activeDir);
string newPath = activeDir;
for (int i = 0; i < 20; i++)
{
//newPath = System.IO.Path.Combine(newPath, "\\" + "dir" + i);
newPath += "\\" + "dir" + i;
Console.WriteLine(newPath);
try
{
Directory.CreateDirectory(newPath);
}
catch (System.UnauthorizedAccessException e) { System.Console.WriteLine(e.Message); }
// string fileNameOne = DateTime.Now.ToString("yyyyMMddHHmmssffff")
// + ".txt";
// string filePathOne = System.IO.Path.Combine(newPath, fileNameOne);
// System.IO.File.Create(filePathOne);
}
}
}
}
循环200次路径太长 没法建立该文件夹 有其他处理办法吗?因为后面要处理遍历目录并输出文件夹名和路径到XML