新建文件夹,如果存在就在原有名称后做累加

 var path = @"E:1";
            var processid = "1";//要创建文件夹的名称
            var VideoPath = string.Empty;
            var filepath = Path.Combine(path, $"{processid}");
            if (!Directory.Exists(filepath))
            {
                Directory.CreateDirectory(filepath);
                VideoPath = filepath;

            }
            else
            {
                int i = 1;
                var filepath2 = string.Empty;
                while (true)
                {
                    var c = processid + $"({i})";
                    filepath2 = Path.Combine(path, $"{c}");
                    if (!Directory.Exists(filepath2))
                    {
                        Directory.CreateDirectory(filepath2);
                        VideoPath = filepath2;
                        break;
                    }
                    else
                    {
                        i++;
                    }
                }               
            }
原文地址:https://www.cnblogs.com/macT/p/11936432.html