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)
{
    //每次讀取一行數據
}
相關文章
相關標籤/搜索