Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
创建目录C#未失败,但未创建文件夹_C#_Asp.net_.net_C# 4.0_Directory - Fatal编程技术网

创建目录C#未失败,但未创建文件夹

创建目录C#未失败,但未创建文件夹,c#,asp.net,.net,c#-4.0,directory,C#,Asp.net,.net,C# 4.0,Directory,可能重复: 我有一个输入目录,其中XML文件是FTP,有一个应用程序运行,然后接收所有这些XML并处理它们。最后,文件将被移动到另一个目录中为其处理日期创建的文件夹中。以下是我尝试创建的路径: D:\srv\test\ftp\Processed\07-19-2012 以下是创建目录的代码: public static bool IfExistOrCreateDirectory(string path, bool createDirIfMissing) { if (Directory.

可能重复:

我有一个输入目录,其中XML文件是FTP,有一个应用程序运行,然后接收所有这些XML并处理它们。最后,文件将被移动到另一个目录中为其处理日期创建的文件夹中。以下是我尝试创建的路径:

D:\srv\test\ftp\Processed\07-19-2012
以下是创建目录的代码:

public static bool IfExistOrCreateDirectory(string path, bool createDirIfMissing) {
    if (Directory.Exists(path)) return true;
    else if (createDirIfMissing) {
        try {
            (new FileInfo(@path)).Directory.Create();
            return true;
        }
        catch (Exception ex) { return false; }
    }
    else return false;
}
此代码运行后,不会抛出任何异常并返回true。但是,当我检查文件夹时,名为“07-19-2012”的文件夹不存在

提前谢谢

PS-在我将一些XML文件从服务器复制到输入文件夹进行测试之前,这段代码一直运行良好。我不能再创建任何驱动器通过代码目录;就好像它们是虚拟创建的。


使用Vlad的解决方案,或使用:


检查站。。。createDirIfMissing的值是多少?是否返回false?原因尝试创建目录时可能会引发异常。。如果函数返回false时没有执行任何操作,那么它可能会被忽略。
Directory.CreateDirectory(path);
(new DirectoryInfo(@path)).Directory.Create();