1

Possible Duplicate:
C# - FileStream and creating folders

I have an input directory where XML files are FTP, there is an app that runs and then ingests all these XML and processes them. At the end, the file is moved to a folder that is created for the date it was processed on inside another directory. Here is the path I attempt to create:

D:\srv\test\ftp\Processed\07-19-2012

Here is the code that creates directories:

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;
}

After this code runs it throws no exceptions and returns true. However, when I check the folder the folder named "07-19-2012" does not exist.

Thanks in advance.

PS- this code was working fine until I copied some XML files down from a server into the input folder to test. I can no longer create directories in any drive through code; it is as if they get created virtually.

Community
  • 1
  • 1
metaphysics
  • 55
  • 1
  • 4
  • checkpoints... whats the value of createDirIfMissing? – dreamerkumar Jul 19 '12 at 18:20
  • is it returning false? cause there could be an exception that was thrown when trying to create the directory.. if nothing is done when the function returns false then it may go unnoticed. – Eric Robinson Jul 19 '12 at 18:21

2 Answers2

1

http://msdn.microsoft.com/en-us/library/54a0at6s.aspx

Directory.CreateDirectory(path);
Vladmir
  • 1,255
  • 9
  • 13
1

Use Vlad's solution, or from http://msdn.microsoft.com/en-us/library/d869eykc use:

(new DirectoryInfo(@path)).Directory.Create();
C.M.
  • 1,474
  • 13
  • 16