using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace Test
{
class PRogram
{
private static void WriteFilePath(Stream filestream)
{
StreamWriter sw = new StreamWriter(filestream);
DirectoryInfo dicInfo = new DirectoryInfo(@"D:\");
FileInfo[] textFiles = dicInfo.GetFiles("*.txt", SearchOption.AllDirectorIEs);
foreach (FileInfo fileInfo in textFiles)
{
sw.WriteLine(fileInfo.FullName);
}
sw.Close();
filestream.Close();
Console.Read();
}
static void Main(string[] args)
{
FileStream fs;
string strFilePath = @"C:\path.txt";
if (File.Exists(strFilePath))
{
fs = new FileStream(strFilePath, FileMode.Open, FileAccess.Write);
WriteFilePath(fs);
}
else
{
fs = new FileStream(strFilePath, FileMode.Create, FileAccess.Write);
WriteFilePath(fs);
}
}
}
}