Site icon Franky's Web

Powershell: List overlong file paths

Overlong file paths can become a problem during migrations and backup/restore processes. A file path must not normally be longer than 260 characters. However, it can happen that this limit is exceeded. This small Powershell script can be used to identify such long paths:

#Directory or volume to be checked:
$Verzeichnis = „D:\Freigaben“

#Ppath to the CSV file for export:
$CSV = „d:\export.csv“

#Write warning level for paths longer than XX characters in CSV
$Warninglevel = „250“

#———————————————–
„Pfad;Laenge“ | set-content „$CSV“
$dirlist = Get-ChildItem „$Verzeichnis“ -recurse | foreach {$_.Fullname}
foreach ($dir in $dirlist)
{
$a = $dir | Measure-Object -Character
$length = $a.characters

if ($length -gt $Warninglevel)
{
„$dir;$length“ | add-content „$CSV“
}
}
$sort = import-csv „$CSV“  -delimiter „;“ | Sort-Object -Property Laenge -Descending
„“ | set-content „$CSV“
$sort | export-csv „$CSV“ -delimiter „;“ –NoTypeInformation

The script searches a directory or a volume and saves the paths that are too long in a CSV file.

Here is some background information: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx

Exit mobile version