Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
Ftt_Common
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Ftt_Common
Commits
44ef276f
Commit
44ef276f
authored
Aug 06, 2025
by
罗显健
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
【编号:22639】搜索功能增加仅搜文件名选项
parent
9beec34f
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
76 additions
and
15 deletions
+76
-15
AssemblyInfo.cs
Tools/Properties/AssemblyInfo.cs
+2
-2
FrmSearch.Designer.cs
WindowsSearch/FrmSearch.Designer.cs
+16
-1
FrmSearch.cs
WindowsSearch/FrmSearch.cs
+58
-12
No files found.
Tools/Properties/AssemblyInfo.cs
View file @
44ef276f
...
...
@@ -10,7 +10,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("FTT-Tools")]
[assembly: AssemblyCopyright("Copyright © 202
4
")]
[assembly: AssemblyCopyright("Copyright © 202
5
")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
...
...
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.
0
.*")]
[assembly: AssemblyVersion("1.
72
.*")]
WindowsSearch/FrmSearch.Designer.cs
View file @
44ef276f
...
...
@@ -37,6 +37,7 @@
this
.
folderBrowserDialog1
=
new
System
.
Windows
.
Forms
.
FolderBrowserDialog
();
this
.
btnSearch
=
new
System
.
Windows
.
Forms
.
Button
();
this
.
pnlTop
=
new
System
.
Windows
.
Forms
.
Panel
();
this
.
ckbSearchFileName
=
new
System
.
Windows
.
Forms
.
CheckBox
();
this
.
pnlSearchType
=
new
System
.
Windows
.
Forms
.
Panel
();
this
.
ckbAll
=
new
System
.
Windows
.
Forms
.
CheckBox
();
this
.
ckbCSharp
=
new
System
.
Windows
.
Forms
.
CheckBox
();
...
...
@@ -100,7 +101,7 @@
|
System
.
Windows
.
Forms
.
AnchorStyles
.
Right
)));
this
.
txtSearchText
.
Location
=
new
System
.
Drawing
.
Point
(
65
,
44
);
this
.
txtSearchText
.
Name
=
"txtSearchText"
;
this
.
txtSearchText
.
Size
=
new
System
.
Drawing
.
Size
(
3
96
,
21
);
this
.
txtSearchText
.
Size
=
new
System
.
Drawing
.
Size
(
3
24
,
21
);
this
.
txtSearchText
.
TabIndex
=
4
;
//
// btnSearch
...
...
@@ -112,9 +113,11 @@
this
.
btnSearch
.
TabIndex
=
7
;
this
.
btnSearch
.
Text
=
"搜索"
;
this
.
btnSearch
.
UseVisualStyleBackColor
=
true
;
this
.
btnSearch
.
Click
+=
new
System
.
EventHandler
(
this
.
btnSearch_Click
);
//
// pnlTop
//
this
.
pnlTop
.
Controls
.
Add
(
this
.
ckbSearchFileName
);
this
.
pnlTop
.
Controls
.
Add
(
this
.
pnlSearchType
);
this
.
pnlTop
.
Controls
.
Add
(
this
.
btnSearch
);
this
.
pnlTop
.
Controls
.
Add
(
this
.
label1
);
...
...
@@ -128,6 +131,17 @@
this
.
pnlTop
.
Size
=
new
System
.
Drawing
.
Size
(
857
,
74
);
this
.
pnlTop
.
TabIndex
=
10
;
//
// ckbSearchFileName
//
this
.
ckbSearchFileName
.
Anchor
=
((
System
.
Windows
.
Forms
.
AnchorStyles
)((
System
.
Windows
.
Forms
.
AnchorStyles
.
Top
|
System
.
Windows
.
Forms
.
AnchorStyles
.
Right
)));
this
.
ckbSearchFileName
.
AutoSize
=
true
;
this
.
ckbSearchFileName
.
Location
=
new
System
.
Drawing
.
Point
(
398
,
46
);
this
.
ckbSearchFileName
.
Name
=
"ckbSearchFileName"
;
this
.
ckbSearchFileName
.
Size
=
new
System
.
Drawing
.
Size
(
60
,
16
);
this
.
ckbSearchFileName
.
TabIndex
=
12
;
this
.
ckbSearchFileName
.
Text
=
"文件名"
;
this
.
ckbSearchFileName
.
UseVisualStyleBackColor
=
true
;
//
// pnlSearchType
//
this
.
pnlSearchType
.
Controls
.
Add
(
this
.
ckbAll
);
...
...
@@ -282,6 +296,7 @@
private
System
.
Windows
.
Forms
.
Panel
pnlSearchType
;
private
System
.
Windows
.
Forms
.
Panel
pnlBottom
;
private
System
.
Windows
.
Forms
.
CheckBox
ckbAll
;
private
System
.
Windows
.
Forms
.
CheckBox
ckbSearchFileName
;
}
}
WindowsSearch/FrmSearch.cs
View file @
44ef276f
...
...
@@ -28,7 +28,6 @@ namespace WindowsSearch
public
FrmSearch
()
{
InitializeComponent
();
this
.
btnSearch
.
Click
+=
new
System
.
EventHandler
(
this
.
btnSearch_Click
);
InitSearchType
();
InitContextMenu
();
...
...
@@ -45,6 +44,7 @@ namespace WindowsSearch
SetType
(
ckbSql
,
"*.sql"
,
true
,
"sql脚本文件"
);
SetType
(
ckbCSharp
,
"*.cs;*.vb;*.resx;*.xsd;*.wsdl;*.htm;*.html;*.aspx;*.ascx;*.asmx;*.svc;*.asax;*.config;*.asp;*.asa;*.cshtml;*.vbhtml;*.razor;*.css;*.xml"
,
false
,
"常规程序文件类型"
);
SetType
(
ckbAll
,
"*.*"
,
false
,
"忽而文件类型,搜所有文件"
);
SetType
(
ckbSearchFileName
,
null
,
false
,
"选中搜文件名,反之搜文件内容"
);
SetSearchType
();
}
...
...
@@ -117,6 +117,10 @@ namespace WindowsSearch
/// <param name="e"></param>
private
void
btnSelectPath_Click
(
object
sender
,
EventArgs
e
)
{
if
(!
string
.
IsNullOrEmpty
(
txtFilePath
.
Text
)
&&
Directory
.
Exists
(
txtFilePath
.
Text
))
{
folderBrowserDialog1
.
SelectedPath
=
txtFilePath
.
Text
;
}
if
(
this
.
folderBrowserDialog1
.
ShowDialog
()
==
DialogResult
.
OK
)
this
.
txtFilePath
.
Text
=
this
.
folderBrowserDialog1
.
SelectedPath
;
}
...
...
@@ -145,10 +149,11 @@ namespace WindowsSearch
kvpSearchTypes
=
ParseSearchType
(
searchTypes
);
btnSearch
.
Enabled
=
false
;
//搜索开始、禁用按钮
var
searchFileName
=
ckbSearchFileName
.
Checked
;
await
Task
.
Factory
.
StartNew
(
async
()
=>
{
await
SearchFiles
(
strFilePath
,
kvpSearchTypes
,
strSearchText
);
await
SearchFiles
(
strFilePath
,
kvpSearchTypes
,
strSearchText
,
searchFileName
);
});
btnSearch
.
Enabled
=
true
;
//搜索结束、启用按钮
...
...
@@ -183,8 +188,9 @@ namespace WindowsSearch
/// <param name="fullPath"></param>
/// <param name="kvpSearchTypes"></param>
/// <param name="searchContent"></param>
/// <param name="searchFileName"></param>
/// <returns></returns>
private
Task
<
List
<
string
>>
SearchFiles
(
string
fullPath
,
List
<
KeyValuePair
<
string
,
Regex
>>
kvpSearchTypes
,
string
searchContent
)
private
Task
<
List
<
string
>>
SearchFiles
(
string
fullPath
,
List
<
KeyValuePair
<
string
,
Regex
>>
kvpSearchTypes
,
string
searchContent
,
bool
searchFileName
=
false
)
{
List
<
string
>
result
=
new
List
<
string
>();
...
...
@@ -198,9 +204,9 @@ namespace WindowsSearch
SetSearchStatus
(
$"准备开始搜索,共
{
files
.
Count
()}
项"
);
// stopWatch.Start();
//
SearchFiles_Type1(files, kvpSearchTypes, searchContent
);
//
SearchFiles_Type1(files, kvpSearchTypes, searchContent, onlyFileName
);
result
=
SearchFiles_Type2
(
files
,
kvpSearchTypes
,
searchContent
);
result
=
SearchFiles_Type2
(
files
,
kvpSearchTypes
,
searchContent
,
searchFileName
);
stopWatch
.
Stop
();
...
...
@@ -220,7 +226,7 @@ namespace WindowsSearch
/// <param name="kvpSearchRegex"></param>
/// <param name="searchContent"></param>
/// <returns></returns>
private
List
<
string
>
SearchFiles_Type2
(
List
<
string
>
files
,
List
<
KeyValuePair
<
string
,
Regex
>>
kvpSearchRegex
,
string
searchContent
)
private
List
<
string
>
SearchFiles_Type2
(
List
<
string
>
files
,
List
<
KeyValuePair
<
string
,
Regex
>>
kvpSearchRegex
,
string
searchContent
,
bool
searchFileName
=
false
)
{
List
<
string
>
result
=
new
List
<
string
>();
...
...
@@ -231,8 +237,9 @@ namespace WindowsSearch
{
if
(
type
.
Value
.
IsMatch
(
filePath
))
{
//文件内容查找,因为文件类型固定,则每个文件只会被读取并查找一次。
if
(
File
.
ReadAllText
(
filePath
).
Contains
(
searchContent
))
//文件内容\文件名查找,因为文件类型固定,则每个文件只会被读取并查找一次。
if
((
searchFileName
&&
IsFileNameMatch
(
filePath
,
searchContent
))
||
(!
searchFileName
&&
IsFileContentMatch
(
filePath
,
searchContent
)))
{
result
.
Add
(
filePath
);
AddSearchFile
(
filePath
);
...
...
@@ -251,7 +258,7 @@ namespace WindowsSearch
/// <param name="kvpSearchRegex"></param>
/// <param name="searchContent"></param>
/// <returns></returns>
private
List
<
string
>
SearchFiles_Type1
(
List
<
string
>
files
,
List
<
KeyValuePair
<
string
,
Regex
>>
kvpSearchRegex
,
string
searchContent
)
private
List
<
string
>
SearchFiles_Type1
(
List
<
string
>
files
,
List
<
KeyValuePair
<
string
,
Regex
>>
kvpSearchRegex
,
string
searchContent
,
bool
onlyFileName
=
false
)
{
List
<
string
>
result
=
new
List
<
string
>();
...
...
@@ -261,7 +268,8 @@ namespace WindowsSearch
var
tFiles
=
files
.
Where
(
f
=>
type
.
Value
.
IsMatch
(
f
)).
ToList
();
foreach
(
var
filePath
in
tFiles
)
{
if
(
File
.
ReadAllText
(
filePath
).
Contains
(
searchContent
))
if
((
onlyFileName
&&
IsFileNameMatch
(
filePath
,
searchContent
))
||
(!
onlyFileName
&&
IsFileContentMatch
(
filePath
,
searchContent
)))
{
result
.
Add
(
filePath
);
AddSearchFile
(
filePath
);
...
...
@@ -273,6 +281,44 @@ namespace WindowsSearch
return
result
;
}
/// <summary>
/// 文件名是否匹配
/// </summary>
/// <param name="filePath"></param>
/// <param name="searchContent"></param>
/// <returns></returns>
private
bool
IsFileNameMatch
(
string
filePath
,
string
searchContent
)
{
// 只匹配文件名
string
fileName
=
Path
.
GetFileName
(
filePath
);
return
fileName
.
IndexOf
(
searchContent
,
StringComparison
.
InvariantCultureIgnoreCase
)
>=
0
;
}
/// <summary>
/// 文件内容是否匹配
/// </summary>
/// <param name="filePath"></param>
/// <param name="searchContent"></param>
/// <returns></returns>
private
bool
IsFileContentMatch
(
string
filePath
,
string
searchContent
)
{
try
{
// 读取文件内容并检查是否包含搜索内容
string
fileContent
=
File
.
ReadAllText
(
filePath
);
return
fileContent
.
IndexOf
(
searchContent
,
StringComparison
.
InvariantCultureIgnoreCase
)
>=
0
;
}
catch
(
Exception
ex
)
{
// 处理文件读取异常(如权限问题等)
Console
.
WriteLine
(
$"Error reading file
{
filePath
}
:
{
ex
.
Message
}
"
);
return
false
;
}
}
#
endregion
private
List
<
KeyValuePair
<
string
,
Regex
>>
ParseSearchType
(
List
<
string
>
fileTypes
)
...
...
@@ -327,7 +373,7 @@ namespace WindowsSearch
/// <param name="tips">提示词</param>
private
void
SetType
(
CheckBox
checkBox
,
string
searchTypes
,
bool
check
=
false
,
string
tips
=
null
)
{
checkBox
.
Text
=
searchTypes
;
if
(!
string
.
IsNullOrEmpty
(
searchTypes
))
checkBox
.
Text
=
searchTypes
;
checkBox
.
Checked
=
check
;
if
(
tips
!=
null
)
toolTip
.
SetToolTip
(
checkBox
,
tips
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment