Skip to content

Commit

Permalink
1、可设置是否打开“图片文件预览”。2、新增“删除时移除空目录”选项。 #3 3、优化。
Browse files Browse the repository at this point in the history
  • Loading branch information
JiuLing-zhang committed Mar 6, 2022
1 parent c9ae6cf commit 7f5de5b
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 10 deletions.
23 changes: 19 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,25 @@

</div>

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

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

## :three: License
* 选项 - 删除时移除空目录
删除文件的时候,如果文件夹中只剩余当前文件,删除的时候会顺便删除文件夹。

* 结果区域 - 一键选中重复文件
自动选中所有重复文件(每个文件只保留一份)。

* 结果区域 - 自定义选择重复文件
弹出筛选窗口,用户可以根据查找路径选择本次要删除的目标文件夹。

* 其它
其它选项都比较通俗易懂,还请同学自行摸索。

![detail.png](https://s2.loli.net/2022/03/06/Oj1hEw3vC7KWZTN.png)

## License
MIT License
2 changes: 1 addition & 1 deletion src/FindDuplicateFiles.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<Win32Resource />
<Authors>九零</Authors>
<Product>重复文件查找</Product>
<Version>1.7.2</Version>
<Version>1.7.3</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
11 changes: 8 additions & 3 deletions src/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
xmlns:local="clr-namespace:FindDuplicateFiles"
mc:Ignorable="d"
Title="重复文件查找"
Height="650" Width="1000"
Height="700"
Width="1000"
MinHeight="700"
MinWidth="1000"
WindowStartupLocation="CenterScreen" Icon="/Images/icon.png"
MouseLeftButtonDown="Window_MouseLeftButtonDown">
<WindowChrome.WindowChrome>
Expand Down Expand Up @@ -94,7 +97,7 @@
<Grid Grid.Column="0" >
<Grid.RowDefinitions>
<RowDefinition Height="120"></RowDefinition>
<RowDefinition Height="200"></RowDefinition>
<RowDefinition Height="240"></RowDefinition>
<RowDefinition Height="240"></RowDefinition>
<RowDefinition Height="50"></RowDefinition>
</Grid.RowDefinitions>
Expand Down Expand Up @@ -124,14 +127,16 @@
<RadioButton Name="RdoOnlyImageFile" Foreground="{DynamicResource FontForeground}" Margin="0,0,0,5">仅查找图片文件</RadioButton>
<RadioButton Name="RdoOnlyMediaFile" Foreground="{DynamicResource FontForeground}" Margin="0,0,0,5">仅查找媒体文件</RadioButton>
<RadioButton Name="RdoOnlyDocumentFile" Foreground="{DynamicResource FontForeground}">仅查找文档文件</RadioButton>
<CheckBox Name="ChkPreviewImage" Foreground="{DynamicResource FontForeground}" Margin="0,10,0,5" ToolTip="点击图片文件时对文件进行预览">启用图片文件预览</CheckBox>
<CheckBox Name="ChkDeleteEmptyDirectory" Foreground="{DynamicResource FontForeground}" Margin="0,2,0,5" ToolTip="如果删除文件后文件夹为空,则删除文件夹">删除时移除空目录</CheckBox>
</StackPanel>
</Border>
</Grid>
<!-- 查找路径 -->
<Grid Grid.Row="2" Background="{DynamicResource GridBackground}" Margin="0,0,7,7">
<Border BorderBrush="{DynamicResource BlockBorder}" BorderThickness="1">
<StackPanel Margin="5">
<TextBlock FontWeight="Bold" Foreground="{DynamicResource FontForeground}" VerticalAlignment="Center">查找路径</TextBlock>
<TextBlock FontWeight="Bold" Foreground="{DynamicResource FontForeground}" VerticalAlignment="Center">查找路径(这里也支持拖拽哦~~)</TextBlock>
<ListBox Name="ListBoxSearchFolders"
ItemsSource="{Binding}"
Height="160"
Expand Down
27 changes: 26 additions & 1 deletion src/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ private void InitializeSearchCondition()
ChkIgnoreSystemFile.IsChecked = true;
ChkIgnoreSmallFile.IsChecked = false;
RdoAllFile.IsChecked = true;
ChkPreviewImage.IsChecked = false;
ChkDeleteEmptyDirectory.IsChecked = false;

_myModel.SearchDirectory.Clear();
}
Expand Down Expand Up @@ -182,6 +184,13 @@ private void AddSearchFolderOnly(string path)
{
return;
}

if (_myModel.SearchDirectory.Any(x => x.DirectoryName.IndexOf(path) == 0 || path.IndexOf(x.DirectoryName) == 0))
{
MessageBox.Show("添加失败:查找路径不能相互包含", "重复文件查找", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}

_myModel.SearchDirectory.Add(new SearchDirectoryModel()
{
DirectoryName = path
Expand Down Expand Up @@ -402,6 +411,11 @@ private void SearchFinished()

private void ListViewDuplicateFile_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (ChkPreviewImage.IsChecked == false)
{
return;
}

var lv = sender as ListView;
if (lv?.SelectedItem is not DuplicateFileModel selectFile)
{
Expand Down Expand Up @@ -490,7 +504,18 @@ private void BtnDeleteFile_Click(object sender, RoutedEventArgs e)
{
continue;
}
System.IO.File.Delete(_myModel.DuplicateFiles[i].Path);

string fileFullName = _myModel.DuplicateFiles[i].Path;
string directory = Path.GetDirectoryName(fileFullName);
if (File.Exists(fileFullName))
{
File.Delete(fileFullName);
}
if (ChkDeleteEmptyDirectory.IsChecked == true && Directory.GetDirectories(directory).Length == 0 && Directory.GetFiles(directory).Length == 0)
{
Directory.Delete(directory);
}

_myModel.DuplicateFiles.RemoveAt(i);
}

Expand Down
4 changes: 4 additions & 0 deletions src/SearchFile/SearchFilesJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ private void EachDirectory(string folderPath, Action<List<string>> callbackFileP
return;
}

if (!Directory.Exists(folderPath))
{
return;
}
Directory.GetDirectories(folderPath).ToList().ForEach(path =>
{
//继续遍历文件夹内容
Expand Down
2 changes: 1 addition & 1 deletion src/Styles/MainWindowStyle.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
<Style x:Key="TitleTheme" TargetType="TextBlock">
<Setter Property="Foreground" Value="{DynamicResource Title}"></Setter>
<Setter Property="VerticalAlignment" Value="Center"></Setter>
<Setter Property="Text" Value="换肤"></Setter>
<Setter Property="Text" Value="主题"></Setter>
</Style>

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

0 comments on commit 7f5de5b

Please sign in to comment.