C# 文件操作
筛选目录下方文件格式
DirectoryInfo dir = new DirectoryInfo(localAddress);
FileInfo[] files = dir.GetFiles("*.log", SearchOption.TopDirectoryOnly);
if (files.Length <= 0)
{
}
移动文件
public static void MoveFileToFold(string localAddress, FileInfo file, string destFold) { DirectoryInfo Finfo = new DirectoryInfo(localAddress + file.Name); string MoveFailPath = localAddress + destFold + "\\"; if (!Directory.Exists(MoveFailPath)) { Directory.CreateDirectory(MoveFailPath); } File.Move(localAddress + file.Name, MoveFailPath + Finfo.Name); File.Delete(localAddress + file.Name); }
读取文件
FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read); StreamReader sr = new StreamReader(fs, System.Text.Encoding.Default); while ((strLine = sr.ReadLine()) != null) { //每次读取一行数据 }