创建一个文件夹而不在代码中提供硬核路径

时间:2010-11-23 12:36:57

标签: c#

我需要在D:\New Folder之类的文本框中提供路径后创建一个名为log的文件夹,而不在var _logFolderPath = @"D:\New Folder\log";代码中提供硬核路径 之后我需要在该日志文件夹中创建两个文本文件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

1 个答案:

答案 0 :(得分:4)

如何将第二行更改为:

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