-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfind_excluded_files.ps1
More file actions
109 lines (93 loc) · 3.44 KB
/
find_excluded_files.ps1
File metadata and controls
109 lines (93 loc) · 3.44 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# Fast PowerShell script to list files not in .cursorignore
# Read .cursorignore file
$ignoreContent = Get-Content -Path ".cursorignore" -ErrorAction SilentlyContinue
$ignorePatterns = @()
foreach ($line in $ignoreContent) {
# Skip comments and empty lines
if ([string]::IsNullOrWhiteSpace($line) -or $line.StartsWith('#')) {
continue
}
# Add the pattern to our list
$ignorePatterns += $line.Trim()
}
# Get all files
Write-Host "Processing files..."
$allFiles = Get-ChildItem -File -Recurse -Path . -ErrorAction SilentlyContinue
# Function to check if a path matches a glob pattern
function Test-GlobMatch {
param (
[string]$Path,
[string]$Pattern
)
# Convert path separators for consistency
$Path = $Path.Replace("\", "/")
# Handle different pattern types
if ($Pattern.EndsWith("/")) {
# Directory pattern - check if the path is in this directory or a subdirectory
$dirPattern = $Pattern.TrimEnd('/')
# Handle **/ prefix for directory patterns
if ($dirPattern.StartsWith("**/")) {
$dirName = $dirPattern.Substring(3)
# Check if path contains the directory at any level
return $Path.Contains("/$dirName/") -or $Path.StartsWith("$dirName/") -or $Path.EndsWith("/$dirName")
}
return $Path.StartsWith("$dirPattern/") -or $Path -eq $dirPattern
}
elseif ($Pattern.StartsWith("**/")) {
# Any directory depth pattern
$suffix = $Pattern.Substring(3)
# Check if path ends with the suffix or contains the suffix as a subdirectory path
return $Path.EndsWith($suffix) -or $Path.Contains("/$suffix")
}
elseif ($Pattern -like "**/*.*") {
# File extension pattern (e.g., **/*.db)
$extension = $Pattern.Substring($Pattern.LastIndexOf("."))
return $Path.EndsWith($extension)
}
elseif ($Pattern.Contains("**")) {
# Create a more flexible regex pattern for ** patterns
$patternParts = $Pattern.Split("**")
$regexPattern = ""
for ($i = 0; $i -lt $patternParts.Length; $i++) {
$part = $patternParts[$i]
$part = [regex]::Escape($part) -replace '\\\*', '[^/]*'
if ($i -lt $patternParts.Length - 1) {
$regexPattern += "$part.*"
} else {
$regexPattern += $part
}
}
return $Path -match $regexPattern
}
elseif ($Pattern.Contains("*")) {
# Simple wildcard pattern
$regexPattern = [regex]::Escape($Pattern) -replace '\\\*', '[^/]*'
return $Path -match "^$regexPattern$"
}
else {
# Exact match
return $Path -eq $Pattern
}
}
# Filter files not in ignore patterns
$includedFiles = @()
foreach ($file in $allFiles) {
$relativePath = $file.FullName.Substring($PWD.Path.Length + 1).Replace("\", "/")
$shouldInclude = $true
# Check against all ignore patterns
foreach ($pattern in $ignorePatterns) {
if (Test-GlobMatch -Path $relativePath -Pattern $pattern) {
$shouldInclude = $false
break
}
}
if ($shouldInclude) {
$includedFiles += $relativePath
}
}
# Write output
"" | Out-File -FilePath "output.txt" -Encoding utf8
foreach ($file in $includedFiles) {
"@$file" | Add-Content -Path "output.txt" -Encoding utf8
}
Write-Host "Done! Check output.txt for results."