writing to a text file is working good...But my problem is text file is created in different path....
Here is my开发者_运维问答 code...
var _logFolderPath = Path.Combine(textboxPath.Text.Trim(), "log");
string[] subdirectoryEntries = Directory.GetDirectories(Path.Combine(txtBoxInput.Text, "RM"));
foreach (string subdirectory in subdirectoryEntries)
{
string[] x = Directory.GetFiles(subdirectory);
DirectoryInfo Folder = new DirectoryInfo(textboxPath.Text);
............
}
and
using (var dest = File.AppendText(Path.Combine(_logFolderPath,subdirectory+ ".txt")))
Here i have to store the subdirectory named text file
in _logFolderPath
path....But the text files are generared in the subdirectory path...I just need the name of the subdirectory to be created as a text file in _logFolderPath
path...How to get the name of the subdirectory alone....Any suggestion?
Have a look at using DirectoryInfo and DirectoryInfo.Name Property
You should use DirectoryInfo instead. It can give you just the directory name. Here is a sample
DirectoryInfo root = new DirectoryInfo("C:\\");
foreach (DirectoryInfo s in root.GetDirectories())
{
Console.Out.WriteLine(s.Name);
}
精彩评论