Simple CreateDirectory with two levels

cboshdave

Member
Joined
Dec 11, 2014
Messages
24
Programming Experience
1-3
I read a bunch of posts about this. Seems simple. I need to add the following folder if it does not exist.

H:\Health Plans\Enrollment\Name 834\2015\05 May\

The base will always exist (H:\Health Plans\Enrollment\Name 834\)
So, I am just doing the following:
C#:
System.IO.Directory.CreateDirectory(sDownloadFolder);
sDownloadFolder = "H:\\Health Plans\\Enrollment\\Name 834\\2015\\05 May\\"

It DOES create the 2015 folder, but will not create the second level for some reason. I have tried several variations and I get nothing for the last level (\05 May\). I am baffled. I even tried to call the same code twice in a row to see if would build each level. Nothing for the second level.

Thoughts?
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
3,150
Location
Sydney, Australia
Programming Experience
10+
I have no idea why that would be the case. I thought maybe it had something to do with the trailing slash but I just tried this:
var path1 = @"C:\Users\jmcilhinney\Documents\Test\A\B\";
var path2 = @"C:\Users\jmcilhinney\Documents\Test\X\Y";

Directory.CreateDirectory(path1);
Directory.CreateDirectory(path2);
and it created all four folders. I also tried this:
var path1 = @"C:\Users\jmcilhinney\Documents\Test\2015\05 May\";

Directory.CreateDirectory(path1);
and it worked fine too.

Is H a mapped network drive? If so, what's the full UNC path? I wonder whether the issue might be that the UNC path is too long, although I'm not sure whether that would even be an issue, as long as the local path isn't.
 
Top Bottom