C# 使用值作为名称创建子文件夹

C# 使用值作为名称创建子文件夹,c#,winforms,path,subdirectory,C#,Winforms,Path,Subdirectory,我正在使用下一个代码在我的项目路径中创建一个文件夹 string projectPath = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName; string folderName = Path.Combine(projectPath, "images"); System.IO.Directory.CreateDirectory(folderName); 它创建一个文件夹图像。。。现在,我想创建一个子

我正在使用下一个代码在我的项目路径中创建一个文件夹

 string projectPath = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName;
 string folderName = Path.Combine(projectPath, "images");
 System.IO.Directory.CreateDirectory(folderName);
它创建一个文件夹
图像
。。。现在,我想创建一个子文件夹,它的名称取自我表单中的文本框值。。每次值更改时,都会创建一个新的子文件夹,并使用新值作为名称

例如,如果我的表单有一个值为
56
的文本框,那么我想在其中创建一个名为
56
的子文件夹
image
文件夹,因此路径将是
…\image\56


如果该值更改为
48
,则使用子文件夹
…\image\48
创建新文件夹。。。etc

您可以将名称与视图值组合,并在创建新文件夹之前测试它是否已存在:

var myValueFromView = "56";
string projectPath = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName;
string folderName = Path.Combine(projectPath, "images", myValueFromView);
if(!System.IO.Directory.Exists(folderName))
    System.IO.Directory.CreateDirectory(folderName);

因此,将
myTextBox.Text
添加为
Path.Combine
中的另一个参数。那么,在将正确的路径与
images
和文本框中的值组合在一起重用当前代码时,您面临什么问题呢?你试过了吗?