/// <summary> /// Closes the module. /// </summary> /// <remarks>Documented by Dev08, 2009-07-15</remarks> private void CloseModule() { SettingsManagerLogic.CloseLearningModule(); TreeViewItems.Clear(); treeViewLearningModule.ItemsSource = null; ExtensionList.Clear(); EnableControls(false); }
//Remove Method private void Remove() { //Date DateTime RawDate = DateTime.Today; string DateDay = (RawDate.Day).ToString(); string DateMonth = (RawDate.Month).ToString(); string DateYear = (RawDate.Year).ToString(); string Date = DateMonth + "-" + DateDay + "-" + DateYear; string LogPath = "C:\\Temp\\TypesFilter " + Date + ".log"; if (File.Exists(LogPath)) { File.Delete(LogPath); } //Count Selected Items foreach (Object SelectedItem in this.Checklist_Types.CheckedItems) { //Search & Remove Files By Selected Types foreach (string GlobalFile in GlobalFilesList) { string PowerShellCMD = "Write-Host 'Removing file: '" + GlobalFile + "; Remove-Item -Path '" + GlobalFile + "' -Force"; string RemoveFileExtension = Path.GetExtension(GlobalFile); if (RemoveFileExtension == SelectedItem.ToString()) { if (GlobalFile != LogPath) { using (StreamWriter LogFile = File.AppendText(LogPath)) { LogFile.WriteLine(GlobalFile); } System.Diagnostics.Process.Start("powershell.exe", PowerShellCMD); } } } } //Clear CheckList this.Checklist_Types.Items.Clear(); RecExtensionList.Clear(); ExtensionList.Clear(); GlobalFilesList.Clear(); RecursiveFlag = false; //Init Labels this.Label_Selection_Extensions.Text = "Extensions "; this.Label_Selection_Files.Text = "Files "; this.Label_Mode.Text = "Mode "; //Scanning this.Label_Folder_Files.Text = "Files "; this.Label_Extensions.Text = "Extensions "; this.Label_Folders.Text = "Folders "; this.Label_Mode.Text = "Mode "; //Folder Path Text is Null this.Label_Directory.Text = null; //Global Variable Modification SelectedFolderPath = null; //Disable Scan Button this.Button_Scan.Enabled = false; //Disable Select All Button this.Button_Select.Enabled = false; //Disable Clear Selection Button this.Button_Clear.Enabled = false; //Disable Recutsive Scan Button this.Button_RecScan.Enabled = false; //Disable Analyze Button this.Button_Analyze.Enabled = false; //Disable Remove Button this.Label_Remove.Enabled = false; //LOG MSG if (File.Exists(LogPath)) { MessageBox.Show("Log file path: " + LogPath); } }
//Scan Method private void Scan() { //Enable Analyze Button this.Button_Analyze.Enabled = true; //Clear Global Files List GlobalFilesList.Clear(); //Set Flag RecursiveFlag = false; //Init Labels this.Label_Selection_Extensions.Text = "Extensions "; this.Label_Selection_Files.Text = "Files "; //Scanning this.Label_Folder_Files.Text = "Files Scanning..."; this.Label_Extensions.Text = "Extensions Scanning..."; this.Label_Folders.Text = "Folders 1"; this.Label_Mode.Text = "Mode: Scan"; //Clear CheckList this.Checklist_Types.Items.Clear(); ExtensionList.Clear(); //Scan string[] Files = Directory.GetFiles(SelectedFolderPath); //Unique Extensions Added to Extenstion List try { foreach (string File in Files) { GlobalFilesList.Add(File); string FileExtension = Path.GetExtension(File); if (ExtensionList.Contains(FileExtension) == false) { ExtensionList.Add(FileExtension); } } } catch { } //Add to CheckList foreach (string Extension in ExtensionList) { this.Checklist_Types.Items.Add(Extension); } //Set Folder Information Label_Folder_Files.Text = "Files " + (Files.Count()).ToString(); Label_Extensions.Text = "Extensions " + (ExtensionList.Count()).ToString(); if (RecursiveFlag == false) { this.Label_Mode.Text = "Mode Non Recursive"; } else { this.Label_Mode.Text = "Mode Recursive"; } //Enable Remove Button this.Label_Remove.Enabled = true; //Init Mode this.Label_Mode.Text = "Mode "; }