tags:

views:

130

answers:

2

i am concatenating a number of variables and i want to save that string as a file path.

is there a way it will automatically create all appropriate directories if they dont exist without having to check "if exists" on each one

for example . .

"C:\" + a + "\" + b+ "\" + d + "\" + d + ".txt"

+3  A: 

Use new FileInfo(path).Directory.Create().

(This creates anything in the hierarchy that's required. If the directory already exists it does nothing.)

Jon Skeet
what if i dont have a file . . i just want to first create the directory??
ooo
See @shahkalpesh's answer.
ProfK
+1  A: 

using System.IO;
....
Directory.CreateDirectory(@"c:\temp\a\b\c\d\e");

shahkalpesh
Don't forget an if (Directory.Exists(...) check.
ProfK