void CopyMove(object sender, RoutedEventArgs e) { TextBlock_Column2.Text = ""; var date = DatePicker.SelectedDate; _periodDays = DatePicker.SelectedDate.HasValue ? (int)(DateTime.Now - DatePicker.SelectedDate.Value).TotalDays : Convert.ToInt32(periodDaysTB.Text); if (periodDaysTB.Text != "" && browsePathTB.Text != "") { _selectPathToWatch = browsePathTB.Text; _targetPath = "C:\\Будет удалено" + DateTime.Now.AddDays(_periodDays).ToString("dd.MM.yyyy"); WorkWithDirectoryWWD.CreateDirectoryToTargetPathWWD001(_targetPath); TextBlock_Column2.Text += "\nУстаревшие Каталоги:\n"; List <string> DirectoriesList = WorkWithDirectoryWWD.GetDirectoriesOlderDatetimeWWD002(_selectPathToWatch, _periodDays); foreach (string i in DirectoriesList) { TextBlock_Column2.Text += i + "\n"; } TextBlock_Column2.Text += "\nУстаревшие Файлы:\n";//+string.Join("",Work_With_DirectoryWWD.GetFiles_Older_Datetime_WWD003(SPstr, Period_Days)); List <string> FilesList = WorkWithDirectoryWWD.GetFilesOlderDatetimeWWD003(_selectPathToWatch, _periodDays); FilesList.ForEach(i => TextBlock_Column2.Text += i + "\n"); /*Movement old files to destination folder */ WorkWithDirectoryWWD.MovementFilesWWD005(_targetPath, FilesList); TextBlock_Column2.Text += $"\nФайлы успешно перемещены: \n{_targetPath}"; WorkWithDirectoryWWD.MovementDirectoriesWWD004(_targetPath, DirectoriesList); TextBlock_Column2.Text += $"\nКаталоги успешно перемещены: \n{_targetPath}"; } }
void CopyMove(object sender, RoutedEventArgs e) { TextBlock_Column2.Text = ""; var date = DateFilterFiles.SelectedDate.Value; try { _periodDays = (int)(DateTime.Now - date).TotalDays; if (browsePathTB.Text != "") { _selectPathToWatch = browsePathTB.Text; WorkWithDirectoryWWD.CreateDirectoryToTargetPathWWD001(_targetPath); TextBlock_Column2.Text += "\nУстаревшие Каталоги:\n"; List <string> DirectoriesList = WorkWithDirectoryWWD.GetDirectoriesOlderDatetimeWWD002(_selectPathToWatch, _periodDays); DirectoriesList.ForEach(i => TextBlock_Column2.Text += i + "\n"); TextBlock_Column2.Text += "\nУстаревшие Файлы:\n"; List <string> FilesList = WorkWithDirectoryWWD.GetFilesOlderDatetimeWWD003(_selectPathToWatch, _periodDays); FilesList.ForEach(i => TextBlock_Column2.Text += i + "\n"); /*Movement old files to destination folder */ WorkWithDirectoryWWD.MovementFilesWWD005(_targetPath, FilesList); TextBlock_Column2.Text += $"\nФайлы успешно перемещены: \n{_targetPath}"; WorkWithDirectoryWWD.MovementDirectoriesWWD004(_targetPath, DirectoriesList); TextBlock_Column2.Text += $"\nКаталоги успешно перемещены: \n{_targetPath}"; /*Create Log.txt*/ using (StreamWriter sw = new StreamWriter(@"C:\Будет удалено\Log.txt", false, System.Text.Encoding.Default)) { sw.WriteLine(DatePicker.SelectedDate.Value.ToString("dd.MM.yyyy")); sw.Close(); } } else { MessageBox.Show("Не заполнен путь к директории"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }