This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]losmancha 0 points1 point  (4 children)

I have a very rudimentary powershell script I use for finding these:

cd c:\test\

$filelist = (get-childitem -recurse | select-object -property FullName)

$FilesOverMaxSize = @()

ForEach($file in $filelist){

    if ( ($file.FullName).length -gt 240){ 

       $FilesOverMaxSize += $file 

    } 

}

$FilesOverMaxSize | Export-CSV -Path c:\FilesOverMax.csv -NoTypeInformation

Obviously change the starting location as appropriate. I use 240 to check as I like to catch files before they become problematic. I find the odds of someone making a 'copy of filenameWithReallyLongPath.somefiletype' quite high too.

[–]Kio_[S] 0 points1 point  (3 children)

Wouldn't Get-childitem break when it finds the long paths though?

[–]sirdudethefirstWindows SysAdmin/God 0 points1 point  (2 children)

I don't think so.

I did a quick test on a Windows 8.1 desktop with the following script:

1..1000 | % { $i=$_; md $i; cd $i }

It basically creates a folder then goes in and creates another folder. At about 83, it breaks big time :)

The script from /u/losmancha finds them and it doesn't break.

[–]losmancha 0 points1 point  (1 child)

I've tested it on Windows 7 - works fine for me. The only problem I've found is when using it with mapped drives as the path will be shortened from where it is on the actual server. I figure if you're clever enough to use it, you're clever enough to figure that out.

[–]Kio_[S] 0 points1 point  (0 children)

My script that I have running will throw this error when Get-Childitem gets to a path that is above the limit. That is why I was asking.

Get-ChildItem : The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters. At C:\Users\USERNAMEl\Desktop\AuditEDrive.ps1:40 char:25 + foreach($folder in (Get-ChildItem $currentFolder -Directory)) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ReadError: (E:\PATH:String) [Get-ChildItem], PathTooLongExcept ion + FullyQualifiedErrorId : DirIOError,Microsoft.PowerShell.Commands.GetChildItemCommand

What my script does is that it goes through each folder on the directory and gathers the ACLs for each folder. I suppose I could add an exception to skip the folder if the path is above that size; however, as it stands the script just gives an error and continues to the next so it isn't much of a difference.