获取磁盘D下所有txt文件路径,并输入到C:\path.txt文件
2009-12-28 10:43:40 来源:WEB开发网核心提示:using System;using System.Collections.Generic;using System.Text;using System.IO;namespace Test{class PRogram{ private static void WriteFilePath(Stream filestrea
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);
}
}
}
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/hanyusong/archive/2009/12/28/5089614.aspx
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);
}
}
}
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/hanyusong/archive/2009/12/28/5089614.aspx
更多精彩
赞助商链接