Это может быть так просто:
import os
cmd = "your command"
os.system(cmd)
Функцию Directory.EnumerateDirectories(string, string)
можно использовать для поиска папок в каталоге, которые соответствуют шаблону. Эта функция демонстрирует пример ее использования, применимый к вашему сценарию:
static bool DirectoryWithPrefixExists(string root, string prefix)
{
return Directory.EnumerateDirectories(root, prefix + "*").Any();
}
bool existsAlready = DirectoryWithPrefixExists(@"C:\root\directory", projectNumber);
Вы можете сделать это:
class Program
{
static void Main(string[] args)
{
string newProjectNumber = "000006"; // new project number you want to add
DirectoryInfo d = new DirectoryInfo(@"C:\Test");//Assuming Test is your Folder
DirectoryInfo[] dirs = d.GetDirectories(); // get the full list of dirs inside C:\Test
foreach (DirectoryInfo dir in dirs) // iterating over dirs
{
string dirName = dir.Name;
if (dirName.Substring(0,6) == newProjectNumber)
{
Console.WriteLine("This folder already exists.");
}
}
Console.ReadLine();
}
}