0

I am trying to output to a text file, all files on a network drive which have a path length greater than x (currently 250).

I have been trying to use the below solution that rerun posted:

How do I find files with a path length greater than 260 characters in Windows?

In powershell cmd /c dir /s /b |? {$_.length -gt 250}

This solution seems to work but has two problems:

  • It is displayed in the Powershell window, not output to a file
  • Powershell formats the windowed results so that one file path is shown over multiple lines. I tried to copy and paste the results from Powershell into an Excel document, but they are pasted over multiple lines in Excel too, and I need each file path on one line

I have changed this solution supplied by rerun to the below:

cmd /c dir /s /b |? {$_.length -gt 250} | Out-File C:\results.txt -width 1500

This now resolves the above two problems, but I run into another issue. I get an error message in the Powershell window when I run it, saying 'The directory name xxxxxxxx is too long'. Checking the file reveals that not all the files have been output to it. Does anybody have an idea of how I can achieve this please? Cheers

Community
  • 1
  • 1
Naz
  • 525
  • 2
  • 9
  • 21
  • If you're looking for a Powershell solution, why are you running `dir` from `cmd.exe`? – alroc Jan 09 '17 at 15:35
  • Im just following the solution that was supplied by rerun, as I dont really know what else to do. But Im also not really familiar with either Powershell or cmd.exe commands, so thought give it a shot – Naz Jan 10 '17 at 16:38

3 Answers3

0

So basically you won't be able to rename or change the properties of the file because file name is too long.

The simplified solution is to rename the file :

Create a winrar file in the same location where your big_named_file is there.

Then press the up button and you should be able to see your big_named_file inside the winrar console.

Press F2 there and there you go , you can rename it.

Note: This is how your file too long issue could be resolved.

Ranadip Dutta
  • 8,857
  • 3
  • 29
  • 45
  • I cant rename the file as I am looking for the files I want to rename. I dont know where they are. The drive is over a TB in size, with hundreds of thousands of files, so difficult to find manually. – Naz Jan 10 '17 at 16:42
  • @Naz : Practically none of the scripts will work here since the file name is too long. and adding to the fire, you have a size of TB, so only left over option is to rename it somehow. This is the best way I have suggested to rename it. I do not think if there is any other way to taclkle it. Look for some third party tool which can do the renaming part atleast. After that only, powershell can pitch in. – Ranadip Dutta Jan 10 '17 at 17:39
  • Hi Ranadip, I dont know where the files are to be able to rename them, so I cannot rename them using this method. First I need to know where they all are, which is why I was looking for a Powershell script that would be able to tell me – Naz Jan 12 '17 at 08:34
  • @Naz : Looks like a critical problem now. Searched for some third party tool ? Nothing else I could think of as if now – Ranadip Dutta Jan 13 '17 at 14:30
0

Instead of dropping out to the old cmd, use get-childitem the following stores the file path in the $files variable, which you could then dump out to a file any way you like, I've used export-csv as you seem to want to see it in Excel.

$files = Get-ChildItem 'yourpath' -recurse | where {$_.fullname.length -gt 250} | select -ExpandProperty fullname
$files | export-csv 'yourfilename' -noclobber
Jim Moyle
  • 637
  • 4
  • 11
  • I get an error in Powershell when I run this: 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 line:1 char:10 + $files = Get-ChildItem '\\server\folder' -recurse | where {$_.full ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ReadError: (\\server\fold...itch - 19.12.12:String) [Get-ChildItem], PathTooLongException + FullyQualifiedErrorId : DirIOError,Microsoft.PowerShell.Commands.GetChildItemCommand – Naz Jan 10 '17 at 16:46
0

That's not really a PowerShell solution. Instead of that, try this which recursively traverses a network path and outputs the long files to longfiles.txt:

gci \\someserver\somedir -r | ? { $_.FullName.length -gt 250 } | select -expandproperty fullname > longfiles.txt
Dave Markle
  • 95,573
  • 20
  • 147
  • 170
  • I get an error in Powershell when I run this command: gci : 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 line:1 char:1 + gci \\server\folder -r | ? { $_.FullName.length -gt 250 } | select ... + ~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ReadError: (\\server\fold...stem - 21.09.12:String) [Get-ChildItem], PathTooLongException + FullyQualifiedErrorId : DirIOError,Microsoft.PowerShell.Commands.GetChildItemCommand – Naz Jan 10 '17 at 16:55