Skip to content

Commit 7f5de5b

Browse files
committed
1、可设置是否打开“图片文件预览”。2、新增“删除时移除空目录”选项。 #3 3、优化。
1 parent c9ae6cf commit 7f5de5b

File tree

6 files changed

+59
-10
lines changed

6 files changed

+59
-10
lines changed

README.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,25 @@
1010

1111
</div>
1212

13-
## FindDuplicateFiles(重复文件查找工具)
14-
一个`.NET 6 WPF`写的 **重复文件查找工具**,解放你的硬盘空间,红盘用户的福音。
13+
![main.png](https://s2.loli.net/2022/03/06/jEdDteQGzLZ3m1l.png)
1514

16-
![FindDuplicateFiles.png](https://i.loli.net/2021/07/24/XiqF6fy8xlrpzwc.png)
15+
## 使用说明
16+
* 选项 - 启用图片文件预览
17+
启用时,在搜索结果中点击图片文件,右下角会出现图片预览结果。
1718

18-
## :three: License
19+
* 选项 - 删除时移除空目录
20+
删除文件的时候,如果文件夹中只剩余当前文件,删除的时候会顺便删除文件夹。
21+
22+
* 结果区域 - 一键选中重复文件
23+
自动选中所有重复文件(每个文件只保留一份)。
24+
25+
* 结果区域 - 自定义选择重复文件
26+
弹出筛选窗口,用户可以根据查找路径选择本次要删除的目标文件夹。
27+
28+
* 其它
29+
其它选项都比较通俗易懂,还请同学自行摸索。
30+
31+
![detail.png](https://s2.loli.net/2022/03/06/Oj1hEw3vC7KWZTN.png)
32+
33+
## License
1934
MIT License

src/FindDuplicateFiles.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<Win32Resource />
1010
<Authors>九零</Authors>
1111
<Product>重复文件查找</Product>
12-
<Version>1.7.2</Version>
12+
<Version>1.7.3</Version>
1313
</PropertyGroup>
1414

1515
<ItemGroup>

src/MainWindow.xaml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
xmlns:local="clr-namespace:FindDuplicateFiles"
77
mc:Ignorable="d"
88
Title="重复文件查找"
9-
Height="650" Width="1000"
9+
Height="700"
10+
Width="1000"
11+
MinHeight="700"
12+
MinWidth="1000"
1013
WindowStartupLocation="CenterScreen" Icon="/Images/icon.png"
1114
MouseLeftButtonDown="Window_MouseLeftButtonDown">
1215
<WindowChrome.WindowChrome>
@@ -94,7 +97,7 @@
9497
<Grid Grid.Column="0" >
9598
<Grid.RowDefinitions>
9699
<RowDefinition Height="120"></RowDefinition>
97-
<RowDefinition Height="200"></RowDefinition>
100+
<RowDefinition Height="240"></RowDefinition>
98101
<RowDefinition Height="240"></RowDefinition>
99102
<RowDefinition Height="50"></RowDefinition>
100103
</Grid.RowDefinitions>
@@ -124,14 +127,16 @@
124127
<RadioButton Name="RdoOnlyImageFile" Foreground="{DynamicResource FontForeground}" Margin="0,0,0,5">仅查找图片文件</RadioButton>
125128
<RadioButton Name="RdoOnlyMediaFile" Foreground="{DynamicResource FontForeground}" Margin="0,0,0,5">仅查找媒体文件</RadioButton>
126129
<RadioButton Name="RdoOnlyDocumentFile" Foreground="{DynamicResource FontForeground}">仅查找文档文件</RadioButton>
130+
<CheckBox Name="ChkPreviewImage" Foreground="{DynamicResource FontForeground}" Margin="0,10,0,5" ToolTip="点击图片文件时对文件进行预览">启用图片文件预览</CheckBox>
131+
<CheckBox Name="ChkDeleteEmptyDirectory" Foreground="{DynamicResource FontForeground}" Margin="0,2,0,5" ToolTip="如果删除文件后文件夹为空,则删除文件夹">删除时移除空目录</CheckBox>
127132
</StackPanel>
128133
</Border>
129134
</Grid>
130135
<!-- 查找路径 -->
131136
<Grid Grid.Row="2" Background="{DynamicResource GridBackground}" Margin="0,0,7,7">
132137
<Border BorderBrush="{DynamicResource BlockBorder}" BorderThickness="1">
133138
<StackPanel Margin="5">
134-
<TextBlock FontWeight="Bold" Foreground="{DynamicResource FontForeground}" VerticalAlignment="Center">查找路径</TextBlock>
139+
<TextBlock FontWeight="Bold" Foreground="{DynamicResource FontForeground}" VerticalAlignment="Center">查找路径(这里也支持拖拽哦~~)</TextBlock>
135140
<ListBox Name="ListBoxSearchFolders"
136141
ItemsSource="{Binding}"
137142
Height="160"

src/MainWindow.xaml.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ private void InitializeSearchCondition()
7676
ChkIgnoreSystemFile.IsChecked = true;
7777
ChkIgnoreSmallFile.IsChecked = false;
7878
RdoAllFile.IsChecked = true;
79+
ChkPreviewImage.IsChecked = false;
80+
ChkDeleteEmptyDirectory.IsChecked = false;
7981

8082
_myModel.SearchDirectory.Clear();
8183
}
@@ -182,6 +184,13 @@ private void AddSearchFolderOnly(string path)
182184
{
183185
return;
184186
}
187+
188+
if (_myModel.SearchDirectory.Any(x => x.DirectoryName.IndexOf(path) == 0 || path.IndexOf(x.DirectoryName) == 0))
189+
{
190+
MessageBox.Show("添加失败:查找路径不能相互包含", "重复文件查找", MessageBoxButton.OK, MessageBoxImage.Error);
191+
return;
192+
}
193+
185194
_myModel.SearchDirectory.Add(new SearchDirectoryModel()
186195
{
187196
DirectoryName = path
@@ -402,6 +411,11 @@ private void SearchFinished()
402411

403412
private void ListViewDuplicateFile_SelectionChanged(object sender, SelectionChangedEventArgs e)
404413
{
414+
if (ChkPreviewImage.IsChecked == false)
415+
{
416+
return;
417+
}
418+
405419
var lv = sender as ListView;
406420
if (lv?.SelectedItem is not DuplicateFileModel selectFile)
407421
{
@@ -490,7 +504,18 @@ private void BtnDeleteFile_Click(object sender, RoutedEventArgs e)
490504
{
491505
continue;
492506
}
493-
System.IO.File.Delete(_myModel.DuplicateFiles[i].Path);
507+
508+
string fileFullName = _myModel.DuplicateFiles[i].Path;
509+
string directory = Path.GetDirectoryName(fileFullName);
510+
if (File.Exists(fileFullName))
511+
{
512+
File.Delete(fileFullName);
513+
}
514+
if (ChkDeleteEmptyDirectory.IsChecked == true && Directory.GetDirectories(directory).Length == 0 && Directory.GetFiles(directory).Length == 0)
515+
{
516+
Directory.Delete(directory);
517+
}
518+
494519
_myModel.DuplicateFiles.RemoveAt(i);
495520
}
496521

src/SearchFile/SearchFilesJob.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ private void EachDirectory(string folderPath, Action<List<string>> callbackFileP
6969
return;
7070
}
7171

72+
if (!Directory.Exists(folderPath))
73+
{
74+
return;
75+
}
7276
Directory.GetDirectories(folderPath).ToList().ForEach(path =>
7377
{
7478
//继续遍历文件夹内容

src/Styles/MainWindowStyle.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
<Style x:Key="TitleTheme" TargetType="TextBlock">
126126
<Setter Property="Foreground" Value="{DynamicResource Title}"></Setter>
127127
<Setter Property="VerticalAlignment" Value="Center"></Setter>
128-
<Setter Property="Text" Value="换肤"></Setter>
128+
<Setter Property="Text" Value="主题"></Setter>
129129
</Style>
130130

131131
<Style x:Key="MenuButton" TargetType="Button" BasedOn="{StaticResource ChangeButtonIsMouseOverNoOpacity}">

0 commit comments

Comments
 (0)