public void Program(MongoClient client) { DS_Form newForm = new DS_Form { TopLevel = true }; newForm.Show(); SourseFolderPath = newForm.DS_OpenFolderDialogForm("Chose folder for checking").ToString(); if (SourseFolderPath == "") { return; } string DirName = Environment.ExpandEnvironmentVariables(@"%USERPROFILE%\Desktop"); dS_Output.DS_WritePath = DirName + "\\" + "Log_ReportStatusExport" + "\\" + CurDateTime + "_" + "Log" + ".txt"; dS_Output.DS_PathNameCreate(CurDateTime, DirName + "\\" + "Log_ReportStatusExport"); Form_ReportDays form_ReportDays = new Form_ReportDays { TopLevel = true }; form_ReportDays.ShowDialog(); int.TryParse(form_ReportDays.textBox_DaysNum.Text, out int DaysNumber); if (DaysNumber == 0) { Environment.Exit(1); } Uploading mongoDB_Test = new Uploading(client); //Iterating through lines in txt file CheckFiles(SourseFolderPath, DaysNumber, mongoDB_Test); CheckDir(SourseFolderPath, DaysNumber, mongoDB_Test); mongoDB_Test.SortPeople(client); MessageBox.Show("Log file has been saved to: " + dS_Output.DS_WritePath); UnloadOpt unloadOpt = new UnloadOpt { TopLevel = true }; unloadOpt.ShowDialog(); MessageBox.Show("Process complete!"); Application.Exit(); }
public static void CheckDir(string CheckPath, int DaysNumber, Uploading mongoDB_Test) { try { //Check folders foreach (string d in Directory.GetDirectories(CheckPath)) { CheckFiles(d, DaysNumber, mongoDB_Test); CheckDir(d, DaysNumber, mongoDB_Test); } } catch (System.Exception excpt) { Console.WriteLine(excpt.Message); } }
public static void CheckFiles(string d, int DaysNumber, Uploading mongoDB_Test) { //Check files in folder // Make a reference to info of a directory. DirectoryInfo di = new DirectoryInfo(d); // Get a reference to each file in that directory. FileInfo[] fiArr = di.GetFiles(); //Extensions list var FileExt = new List <string> { ext }; List <string> FileFullNames = Directory.EnumerateFiles(d, "*_*_*_*_*_*_*_*", SearchOption.TopDirectoryOnly). Where(s => FileExt.Contains(Path.GetExtension(s).TrimStart((char)46).ToLowerInvariant())).ToList(); foreach (string fn in FileFullNames) { FileInfo f = new FileInfo(fn); List <string> field = new List <string>(); if (f.LastWriteTime > DateTime.Now.AddDays(-DaysNumber)) { char[] charsToTrim = { ' ' }; string[] SplitString = f.LastWriteTime.ToString().Split(charsToTrim); //LastWriteDate field.Add(SplitString[0]); //LastWriteTime field.Add(SplitString[1]); //Length field.Add(f.Length.ToString()); //Directory name field.Add(f.DirectoryName); //File name parsing string line = f.Name; field.AddRange(FieldsGet(line)); if (Uploading.ColName == null) { Uploading.ColName = DateTime.Now.ToString("yyMMdd") + "_" + field[8] + "_" + field[10] + "_" + ext + "_" + DaysNumber; mongoDB_Test.CheckCollectionsNames(); dS_Output.DS_StreamWriter("\n" + "Files has been found: "); } dS_Output.DS_StreamWriter(f.Name); mongoDB_Test.InsertOneDoc(field); } } }