-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfind.ps1
37 lines (30 loc) · 1.05 KB
/
find.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
function find {
Param(
[Parameter(Mandatory)]
[string]$Search,
[Parameter(HelpMessage="Don't include sub directories")]
[switch]$NoRecurse = $false,
[Parameter(HelpMessage="Interprets the search term as regular expression")]
[switch]$UseRegEx = $false,
[Parameter(HelpMessage="Definde file type filters here")]
[string]$Filter = "*.*",
[Parameter(HelpMessage="Show only file names, no paths")]
[switch]$NoPath
)
if ($UseRegEx) {
$escapedSearch = $Search
} else{
$escapedSearch = [Regex]::Escape($Search)
}
if ($noPath)
{
$listStyle = "FileName"
} else {
$listStyle = "Path"
}
if ($NoRecurse) {
Get-Childitem -filter $Filter | Select-String -Pattern $escapedSearch -ErrorAction SilentlyContinue | Select-Object $listStyle -Unique
} else {
Get-Childitem -filter $Filter -Recurse | Select-String -Pattern $escapedSearch -ErrorAction SilentlyContinue | Select-Object $listStyle -Unique
}
}