String path =
@"X:\xxx\xxx"
;
var
files = Directory.GetFiles(path,
"*.txt"
);
foreach
(
var
file
in
files)
Console.WriteLine(file);
DirectoryInfo folder =
new
DirectoryInfo(path);
foreach
(FileInfo file
in
folder.GetFiles(
"*.txt"
))
{
Console.WriteLine(file.FullName);
}
string fullPath = @"\WebSite1\Default.aspx";
string filename = System.IO.Path.GetFileName(fullPath);//文件名 “Default.aspx”
string extension = System.IO.Path.GetExtension(fullPath);//扩展名 “.aspx”
string fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(fullPath);// 没有扩展名的文件名 “Default
用数据流读取文件的文件,获取特定的符号
public string SelectStr(string str)
{
//FileStream fs = new FileStream("C:\\Users\\Microsoft\\Desktop\\test\\test.txt", FileMode.Open);
//string fullPath = @"\WebSite1\Default.aspx";
//string filename = System.IO.Path.GetFileName(fullPath);//文件名 “Default.aspx”
string path = "C:\\Users\\Microsoft\\Desktop\\test";
var files = Directory.GetFiles(path, "*.txt");
var file = files[0];
//string filename = System.IO.Path.GetFileName(file);
//foreach (var file in files)
// Console.WriteLine(file);
FileStream fs = new FileStream(file, FileMode.Open);
StreamReader m_streamReader = new StreamReader(fs, System.Text.Encoding.GetEncoding("GB2312"));
m_streamReader.BaseStream.Seek(0, SeekOrigin.Begin);
string strLine = m_streamReader.ReadLine();
do
{
if (strLine.Contains(str))
{
//return strLine.Substring(strLine.IndexOf(str) - 1, 1);
MessageBox.Show("P");
break;
}
strLine = m_streamReader.ReadLine();
} while (strLine != null && strLine != "");
m_streamReader.Close();
m_streamReader.Dispose();
fs.Close();
fs.Dispose();
return "";
}