public static void RemoveMsg(SaveFilePars _pars, string _extention) { string ret = Remove(_pars, _extention); if (ret == null) { return; } MessageBox.Show(ret, "Внимание!!!"); }
public static string Remove(SaveFilePars _pars, string _extention) { if (_pars.Path == null) { return(null); } if (_pars.MaxNumber == null) { return(null); } if (_pars.MaxNumber.Value == 0) { return(null); } DirectoryInfo di = new DirectoryInfo(_pars.Path); if (!di.Exists) { return(null); } FileInfo[] Lfi = di.GetFiles("*." + _extention); if (Lfi.Length <= _pars.MaxNumber.Value) { return(null); } Array.Sort(Lfi, (x, y) => StringComparer.OrdinalIgnoreCase.Compare(x.LastWriteTime, y.LastWriteTime)); //for (int i = 0; i < Lfi.Length; i++) //{ // pr("--- " + Lfi[i].Name + " " + Lfi[i].LastWriteTime.ToLocalTime()); //} for (int i = 0; i < Lfi.Length - _pars.MaxNumber.Value; i++) { try { pr(Lfi[i].Name + " " + Lfi[i].LastWriteTime.ToLongDateString()); Lfi[i].Delete(); } catch (Exception e) { return("Не могу удалить файл: " + Lfi[i].FullName + " " + e.Message); } } return(null); }
//string SQLZoneList(int _iis, double _gain) //{ // string ret = null; // for (int iz = 0; iz < MZone.Count; iz++) // { // ret += string.Format("{0}Z{1}={2}", // iz == 0 ? "" : ",", // (iz + 1).ToString(), // Math.Round(MZone[iz].MSensor[_iis].Level * _gain, 5).ToString(NFI)); // } // return (ret); //} public void SaveBINDKB2_Msg() { SaveFilePars spars = ParAll.ST.Defect.Some.SaveFile; RemoveFiles.RemoveMsg(spars, "bindkb2"); if (spars.Path == null || spars.Path.Length == 0) { return; } try { SaveBINDKB2(FileName); } catch (Exception e) { System.Windows.Forms.MessageBox.Show("Не могу записать файл: " + FileName + " " + e.Message); } }