luoyvtianxiang 2017-11-14 05:57 采纳率: 0%
浏览 2950

C# Directory.CreateDirectory建立多层文件夹目录 路径长度过长问题

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

  • 写回答

3条回答

  • qq_34292368 2017-11-14 07:32
    关注

    这个是操作系统问题,不是程序问题吧!

    评论

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题