-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlong_paths_v1.ps1
38 lines (35 loc) · 1.27 KB
/
long_paths_v1.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
38
$Path = "C:\" # Specify the root directory to start the search
$MaxLength = 260 # Define the maximum path length limit
$OutputFile = "C:\long_paths.txt" # Output file to store results
# Custom function to handle long paths
function Get-FilesWithLongPath {
param (
[string]$Path,
[int]$MaxLength
)
$items = New-Object System.Collections.ArrayList
# Enumerate all files
[System.IO.Directory]::EnumerateFiles($Path, "*", [System.IO.SearchOption]::AllDirectories) | ForEach-Object {
try {
if ($_ -and $_.Length -gt $MaxLength) {
$null = $items.Add($_)
}
} catch {
Write-Warning "Error accessing: $_"
}
}
# Enumerate all directories
[System.IO.Directory]::EnumerateDirectories($Path, "*", [System.IO.SearchOption]::AllDirectories) | ForEach-Object {
try {
if ($_ -and $_.Length -gt $MaxLength) {
$null = $items.Add($_)
}
} catch {
Write-Warning "Error accessing: $_"
}
}
return $items
}
# Call the function and output results
Get-FilesWithLongPath -Path $Path -MaxLength $MaxLength | Out-File -FilePath $OutputFile
Write-Host "Results saved to $OutputFile"