Actions

Powershell: Long File Names

From Rabbi Blog

Revision as of 11:29, 25 September 2019 by Rabbi Bob (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Sometimes knowing ahead of time that long file names are present is helpful.

Change $maxlength to fit your needs.

Within the loop, you can do what you want with the list: output to file, etc.

Example code


$maxlength = 250
$longfilelist = cmd /c dir "C:\windows\" /s /b |? {$_.length -gt $maxlength}

foreach ($longfile in $longfilelist) {
    $filelength=$longfile.length
    Write-Host "$filelength - $longfile"}