Skip to main content
 首页 » 编程设计

c#之创建一个文件夹而不在代码中给出硬核路径

2024年02月23日17Leo_wl

我需要在像 D:\New Folder 这样的文本框中给出路径后创建一个名为 log 的文件夹,而不在像 var _logFolderPath = @"D 这样的代码中给出核心路径:\新建文件夹\日志"; 然后我需要在该日志文件夹中创建两个文本文件 ba.txt 和 ra.txt

这是我的代码

 DirectoryInfo Folder = new DirectoryInfo(textboxPath.Text); 
 var _logFolderPath =textboxPath.Text; 
 if (Folder.Exists) 
 if (!Directory.Exists(_logFolderPath)) Directory.CreateDirectory(_logFolderPath); 

和

  using (var dest = File.CreateText(Path.Combine(_logFolderPath, line2 + ".txt"))) 

供引用 comparing two text files

请您参考如下方法:

如何将第 2 行更改为:

var _logFolderPath = Path.Combine(textboxPath.Text.Trim(), "log");