string path = @"C:\程序部分\实践\FileForeach\FileForeach\Files\";
string savePath = path + "sb.txt";
if (!File.Exists(savePath))
{
File.Create(savePath);
MessageBox.Show("创建成功");
}
else
{
MessageBox.Show("文件已存在");
}
public class WriteFlush
{
public static void WriteText(string path, string savePath)
{
string[] Files = Directory.GetFiles(path);
string[] Direction = Directory.GetDirectories(path);
FileInfo f = new FileInfo(savePath);
var s = f.AppendText();
s.WriteLine("文件夹:");
foreach (var dir in Direction)
{
s.WriteLine(dir);
}
s.WriteLine("文件:");
foreach (var files in Files)
{
s.WriteLine(files);
}
s.Flush();
}
}
C#遍历某个文件夹的文件及子文件夹
最新推荐文章于 2024-03-11 10:18:04 发布