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

            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;
                bool status = false;     
                 var filepath2 = string.Empty;
                while (status != true)
                {
                    var c = processid + $"({i})";
                    filepath2 = Path.Combine(path, $"{c}");
                    if (!Directory.Exists(filepath2))
                    {
                        Directory.CreateDirectory(filepath2);
                        status = true;
                    }
                    else
                    {
                        i++;
                    }
                }
                if (status)
                {
                    VideoPath = filepath2;
                }
            }

猜你喜欢

转载自www.cnblogs.com/macT/p/11936432.html