/// <summary> /// 递归删除文件夹下所有文件 /// </summary> /// <param name="strDir"></param> public static void Del_Files4Dir(string strDir) { if (strDir.IsNullOrWhiteSpace()) { return; } if (!Directory.Exists(strDir)) { return; } var full_Names = GetAll_Files4Dir(strDir); for (int i = 0; i < full_Names.Length; i++) { try { var m_File_Status = FileExt.Check_Status(full_Names[i]); if (m_File_Status == File_Status.Unlocked) { File.Delete(full_Names[i]); } } catch (Exception ex) { NLogHelper.Error(ex); } } }
/// <summary> /// Safe_ReadAllText,先复制再读取信息 /// </summary> /// <param name="strSrc_File"></param> /// <param name="strTarget_File"></param> public static string Safe_ReadAllText(string strSrc_File, string strTarget_File) { try { var file_status = FileExt.Check_Status(strSrc_File); switch (file_status) { case File_Status.NonExisting: return(""); default: break; } File.Copy(strSrc_File, strTarget_File, true); string strRtn = File.ReadAllText(strTarget_File); return(strRtn); } catch (Exception ex) { } return(""); }
/// <summary> /// 从 strSrc_File 文件 安全加载“实时信息”,位于文本文件第一行 /// </summary> /// <param name="strSrc_File"></param> /// <param name="strTarget_File"></param> /// <param name="errorMsg"></param> /// <returns></returns> public static string GetLine0_4Txt(string strSrc_File, string strTarget_File, ref string errorMsg) { errorMsg = ""; try { var file_status = FileExt.Check_Status(strSrc_File); switch (file_status) { case File_Status.NonExisting: errorMsg = "数据文件不存在"; return(""); default: break; } File.Copy(strSrc_File, strTarget_File, true); var lines = File.ReadAllLines(strTarget_File); if (lines == null || lines.Length == 0) { return(""); } string strRtn = lines[0]; return(strRtn); } catch (Exception ex) { errorMsg = ex.Message; } return(""); }