Automatically create folders in C # directory

I need a script that can automatically create subfolders.

For example:

I have a base folder stored in c:/upload . I will go to the line script: /2011/23/12/3 2011/23/12/3. The script should parse this line and create folders and subfolders in c:/upload , just like the line (should be c:/upload/2011/23/12/3 )

How can i do this?

Now I use if / else and check if the folder / subfolder exists, but the script is tooooo big and this is hard to handle.

+7
source share
3 answers

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

From the documentation:

All directories specified in the path are created if they no longer exist or if some part of the path is invalid.

+18
source

Your cataloging code will recursively be as simple as:

 Directory.CreateDirectory(path) 
+6
source

You can use Directory.CreateDirectory in C # to create a directory.

+1
source

All Articles