public void DeleteFile(string current_file_name, string current_directory, string filter) { DirectoryInfo current_directory_info = null; // Parse the directory and file name using the driving data. if (!string.IsNullOrEmpty(current_directory)) { current_directory = TextParser.Parse(current_directory, DrivingData, SharedData, ModuleCommands); } else { current_directory = TextParser.Parse(SharedData.TempFileDirectory, DrivingData, SharedData, ModuleCommands); } current_file_name = TextParser.Parse(current_file_name, DrivingData, SharedData, ModuleCommands); Logger.WriteLine("LanCleaner.Process", "", System.Diagnostics.TraceEventType.Information, 2, 0, SharedData.LogCategory); Logger.WriteLine("LanCleaner.Process", " SOURCE DIRECTORY: " + current_directory, System.Diagnostics.TraceEventType.Information, 2, 0, SharedData.LogCategory); Logger.WriteLine("LanCleaner.Process", " SEARCH PATTERN: " + current_file_name, System.Diagnostics.TraceEventType.Information, 2, 0, SharedData.LogCategory); // Verify the directory exists. if (System.IO.Directory.Exists(current_directory)) { // Get the directory the cleaner is referencing. current_directory_info = new DirectoryInfo(current_directory); // Collect the files. If a wildcard is used in the name, multiple files could be returned. var file_list = current_directory_info.GetFiles(current_file_name, SearchOption.TopDirectoryOnly).ToList(); Logger.WriteLine("LanCleaner.Process", " MATCHED FILE COUNT: " + file_list.Count, System.Diagnostics.TraceEventType.Information, 2, 0, SharedData.LogCategory); foreach (FileInfo info in file_list) { Logger.WriteLine("LanCleaner.Process", " MATCHED: " + info.Name, System.Diagnostics.TraceEventType.Information, 2, 0, SharedData.LogCategory); // Add the current file results to the modules global output table. SetModuleCommands(info); AddResults(); } Logger.WriteLine("LanCleaner.Process", "", System.Diagnostics.TraceEventType.Information, 2, 0, SharedData.LogCategory); if (!string.IsNullOrEmpty(filter)) { Logger.WriteLine("LanCleaner.Process", " FILTER: " + TextParser.Parse(filter, DrivingData, SharedData, ModuleCommands), System.Diagnostics.TraceEventType.Information, 2, 0, SharedData.LogCategory); } foreach (DataRow row in GlobalOutputTable.Select(TextParser.Parse(filter, DrivingData, SharedData, ModuleCommands))) { // Delete the files that meet the filter criteria. Logger.WriteLine("LanCleaner.Process", " DELETING: " + row["FileName"].ToString(), System.Diagnostics.TraceEventType.Information, 2, 0, SharedData.LogCategory); System.IO.File.Delete(row["FileFullName"].ToString()); // Copy the files the module deleted to the DeleteFilesTable. DeletedFilesTable.Rows.Add(row.ItemArray); } // Accept the new rows to the table. DeletedFilesTable.AcceptChanges(); // Clear all the rows from the modules global output table. // This needs to be done because at this point the table will contain all files that // matched the results of CurrentDirectoryInfo.GetFiles and not just the files that // met the filter criteria. Once processing is complete for the module the global cache table // will be updated with the DeletedFilesTable. GlobalOutputTable.Rows.Clear(); } }