Created
June 11, 2019 14:34
-
-
Save stuartd/7e15b2a22c853dc56f8f75924bfd78c4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var name = "directory name"; | |
var path = @"c:\temp\dirtest"; | |
for (int i = 0; i < 12; i++) | |
{ | |
CreateDirectory(name, path); | |
} | |
void CreateDirectory(string directoryName, string filePath) | |
{ | |
var basePath = Path.Combine(filePath, directoryName); | |
if (!Directory.Exists(basePath)) | |
{ | |
Directory.CreateDirectory(basePath); | |
return; | |
} | |
/* | |
"directory name" | |
"directory name (1)" | |
"directory name (2)" | |
etc | |
*/ | |
var matches = Directory.GetDirectories(path, $"{directoryName} (*)"); | |
Directory.CreateDirectory(Path.Combine(filePath, directoryName + $" ({matches.Length + 1})")); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment