public static bool BuildLists(string baseDir) { if (RemoveDirs == null) { RemoveDirs = new List <string>(); } if (RemoveFiles == null) { RemoveFiles = new List <string>(); } RemoveDirs.Clear(); RemoveFiles.Clear(); DocsToKeep.Clear(); string[] dirs = Directory.EnumerateDirectories(baseDir, "*", SearchOption.AllDirectories).ToArray(); bool hasMultiCsv = dirs.Any(x => x.Contains(_csvDir)); if (!hasMultiCsv) { return(false); } AppConst.SetDataCsvPath(dirs.Where(x => x.TrimEnd(Path.DirectorySeparatorChar).EndsWith(_csvDir)).First()); for (int x = 0; x < dirs.Length; x++) { if (!AppConst.DataCsvPath.Contains(dirs[x]) && !dirs[x].Equals(AppConst.TmpPath)) { RemoveDirs.Add(dirs[x]); } else { if (!dirs[x].Equals(AppConst.DataCsvPath) && !dirs[x].Equals(AppConst.TmpPath)) { RemoveFiles.AddRange(Directory.EnumerateFiles(dirs[x])); } } } string docsDir = dirs.Where(x => x.Contains("Documents")).FirstOrDefault(); if (!string.IsNullOrEmpty(docsDir)) { var docfiles = Directory.EnumerateFiles(docsDir, "*.csv").ToList(); var cRegex = new Regex(_countyRegex, RegexOptions.IgnoreCase); for (int x = 0; x < docfiles.Count; x++) { if (cRegex.IsMatch(docfiles[x])) { DocsToKeep.Add(docfiles[x]); } } } if (DocsToKeep.Count != AppConst.ExpectedDocumentsCount) { if (DocsToKeep.Count == 0) { //scan tmp for csv files if (Directory.Exists(AppConst.TmpPath)) { DocsToKeep = Directory.EnumerateFiles(AppConst.TmpPath, "*.csv").ToList(); } } if (DocsToKeep.Count != AppConst.ExpectedDocumentsCount) { Console.Write("DOCUMENT COUNT INCORRECT - "); } } return(true); }