Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatic create folders in directory c#

I need a script that can create a sub folders automaticaly.

For example:

I have a base folder stored at c:/upload. I tranfer to script folders string: /2011/23/12/3. Script should parse this string and create folders and subfolders in c:/upload like string is (should be c:/upload/2011/23/12/3)

How can I make this?

Now I use if/else and check if folder/subfolder exist, but the script is tooooo big and that is hard to manage.

like image 272
Evgeniy Labunskiy Avatar asked May 27 '11 07:05

Evgeniy Labunskiy


3 Answers

Have you looked at Directory.CreateDirectory, which will create any missing directories along the way?

From the documentation:

Any and all directories specified in path are created, unless they already exist or unless some part of path is invalid.

like image 72
Jon Skeet Avatar answered Nov 05 '22 09:11

Jon Skeet


Your code to create directories recursively will be as simple as:

Directory.CreateDirectory(path)
like image 38
Aamir Avatar answered Nov 05 '22 08:11

Aamir


You can use Directory.CreateDirectory in C# for creating directory.

like image 28
Wills Avatar answered Nov 05 '22 08:11

Wills