示例#1
0
        private async Task DeleteContents()
        {
            var files          = ScanHelper.GetFiles(SourceDir, keywords: Keywords);
            var subDirectories = ScanHelper.GetSubDirectories(SourceDir, excludeEmpty: ExcludeEmptyDirectories);

            if (Frequency == FrequencyEnum.AfterDays)
            {
                files          = ScanHelper.FilterFilesByAge(DayLimit, files);
                subDirectories = ScanHelper.FilterDirectoriesByAge(DayLimit, subDirectories);
            }

            ScanHelper.DeleteFiles(files);
            ScanHelper.DeleteDirectories(subDirectories);
        }
        private void ShowWindow()
        {
            try
            {
                Instance = this;

                var settings = SettingsHelper.LoadSettings();
                Instance.Left = settings.PromptWindowLeft;
                Instance.Top  = settings.PromptWindowTop;

                SourceDirectory = new DirectoryInfo(ActiveRule.SourceDir);
                NewFileList     = SourceDirectory.GetFiles().ToList();

                if (ActiveRule.IncludeSubDirectories)
                {
                    SubDirectories = ScanHelper.GetSubDirectories(ActiveRule.SourceDir, excludeEmpty: ActiveRule.ExcludeEmptyDirectories);
                }
                else
                {
                    SubDirectories = new List <DirectoryInfo>();
                }

                SubDirectories.ForEach(d => newFilesListBox.Items.Add($"{d.Name} (Dir)"));
                NewFileList.ForEach(f => newFilesListBox.Items.Add($"{f.Name}"));

                sourceLabel.Content   = SourceDirectory.FullName.Length > 20 ? $"Source: ...\\{SourceDirectory.FullName.Substring(3, 17)}" : $"Source: {SourceDirectory.FullName}";
                contentsLabel.Content = $"Contents: {newFilesListBox.Items.Count}";

                addButton.Click    += (s, e) => SelectFile();
                removeButton.Click += (s, e) => UnselectFile();

                Instance.ShowDialog();
            }
            catch (Exception ex)
            {
                LogHelper.LogError(ex);
            }
        }