Powershell: Long File Names: Difference between revisions
From Rabbi Blog
(Created page with "Sometimes knowing ahead of time that long file names are present is helpful. Example code ------------ <pre> $maxlength = 214 $longfilelist = cmd /c dir "C:\windows\" /s /...") |
mNo edit summary |
||
Line 1: | Line 1: | ||
Sometimes knowing ahead of time that long file names are present is helpful. | 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 | Example code | ||
Line 5: | Line 9: | ||
------------ | ------------ | ||
<pre> | <pre> | ||
$maxlength = | $maxlength = 250 | ||
$longfilelist = cmd /c dir "C:\windows\" /s /b |? {$_.length -gt $maxlength} | $longfilelist = cmd /c dir "C:\windows\" /s /b |? {$_.length -gt $maxlength} | ||
Latest revision as of 11:29, 25 September 2019
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"}