I need to create a directory, but, the directory when I need to create is inside of another directory. Something like this:
Directory.CreateDirectory(@"teste\teste\teste\teste\");
basically, this directory does not exist ( of course ), but, the CreateDirectory(...) not support this string style, how I can make to create this directories ?
My way to make this is that:
private void createdir(string _path)
{
string path = string.Empty;
string[] dir = _path.Split('\\');
for(int i=0;i<dir.Length;i++)
{
path += dir[i] + "\\";
Directory.CreateDirectory(path);
}
}
But, I want to know, if have a more better way to make this ( a more legible ) more rapid.
Directory.Create("c:\teste\teste\teste\teste"); should workt
according to MSDN, you can nest the directory . CreateDirectory
Directory.CreateDirectory("Public\\Html");
Directory.CreateDirectory("\\Users\\User1\\Public\\Html");
Directory.CreateDirectory("c:\\Users\\User1\\Public\\Html"); // using verbatim string you can escape slashes
if(System.IO.Directory.Exists(yourPath))
{
Directory.CreateDirectory(yourPath);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With