Actions

Difference between revisions of "Powershell: Long File Names"

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 /...")
 
m
 
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 = 214
+
$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 06: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"}