开发者

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.


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.


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

Directory.CreateDirectory(path)


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜