【问题标题】:DirectoryInfo Class Exists false if a folder contains spaces between nameDirectoryInfo Class Exists false 如果文件夹在名称之间包含空格
【发布时间】:2013-07-08 06:41:30
【问题描述】:
string ActualPath = "D:\Files\a             c"

DirectoryInfo di = DirectoryInfo(ActualPath);

当文件夹在名称之间包含空格时,di.Exist 始终为假...代码中的问题是什么...目录实际存在的位置。

提前谢谢...

【问题讨论】:

    标签: asp.net directoryinfo


    【解决方案1】:

    我认为问题不在于空格。我认为问题在于您需要为路径中的反斜杠使用正确的转义序列,例如。

    string ActualPath = "D:\\Files\\a             c";
    

    string ActualPath = @"D:\Files\a             c";
    

    试试

    string ActualPath = @"D:\Files\a             c";
    DirectoryInfo di = new DirectoryInfo(ActualPath);   
    if (di.Exists)
    {
       //do something
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-23
      • 1970-01-01
      • 2012-09-30
      • 1970-01-01
      • 2020-09-29
      • 1970-01-01
      • 2020-11-14
      • 1970-01-01
      相关资源
      最近更新 更多