Reputation: 1112
Using
Directory _dir = Directory.CreateDirectory(path);
So how to store the object of directory in a variable so then I have to check whether the directory at specified path exists or not as?
if(!_dir.exists())
{
_dir.CreateDirectory(path);
}
Is it allowed in C#?
Upvotes: 0
Views: 141
Reputation: 54
Try This...
string path=@"C:\Users\v\Desktop\DESKTOP";
if(!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
Upvotes: 2
Reputation: 1806
DirectoryInfo dir = Directory.CreateDirectory(path);
if(!dir.Exists)
{
dir.CreateDirectory(path);
}
Or
DirectoryInfo dir = Directory.CreateDirectory(path);
if(!Directory.Exists(path))
{
dir.CreateDirectory(path);
}
Upvotes: 0