C# 在C中将文件夹名放入txt文件#

C# 在C中将文件夹名放入txt文件#,c#,C#,我正在尝试将文件夹名称写入txt文件。到目前为止,我在这里 string yol = Application.StartupPath + "\\isimler.txt"; System.IO.StreamWriter zzz = new System.IO.StreamWriter(yol); string[] lines = Directory.GetDirectories(@"C:\test"); zzz.WriteLine(lines); zzz.Close(); 如何将文件夹名称写入t

我正在尝试将文件夹名称写入txt文件。到目前为止,我在这里

string yol = Application.StartupPath + "\\isimler.txt";
System.IO.StreamWriter zzz = new System.IO.StreamWriter(yol);
string[] lines = Directory.GetDirectories(@"C:\test");
zzz.WriteLine(lines);
zzz.Close();

如何将文件夹名称写入txt文件?

使用
Directory.GetDirectories
获取指定目录中的所有文件夹名称,然后遍历它并写入.txt文件。 代码片段如下所示:

string yol =  "isimler.txt";
System.IO.StreamWriter zzz = new System.IO.StreamWriter(yol);
string[] lines = Directory.GetDirectories(@"C:\");
foreach(string name in lines)
    zzz.WriteLine(name);
zzz.Close();

您是否尝试过使用
Path.GetDirectoryName
FileInfo.Directory
等。在询问SOI之前,请尝试使用google。我没有尝试
Path.GetDirectoryName
FileInfo.Directory
等。我也尝试了谷歌作为主题,还将文件夹放入字符串等。EZI感谢lightning。我可以在另一个地方列出文件夹名称,我想要的是将它们写入txt文件。2减号是什么?子目录呢?递归字符串中的子目录[]我不是问为什么我不知道该做什么,只是为了帮助你改进你的问题。但既然它已经被接受了,就忘了它吧。人们可以接受这个愚蠢的回答很抱歉打破了你的梦想EZI。并不是说我没有想过,只是不需要问。人们可以接受这个垃圾答案,问题是人们在乎吗?