4

I'm trying to generate a list of all known files on a file share with Attributes Archive and Offline.

But I keep running into PathTooLongException errors.

So far I've only found that Robocopy can work past the file length errors except that I can't get the same sort of "these attributes only" sort of results.

Example:

Get-ChildItem -Attributes A+O -Recurse |Export-Csv E:\temp\StubSearchCorp.csv

Gives:

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:1
+ Get-ChildItem -Attributes A+O -Recurse |Export-Csv E:\temp\StubSearchA.Corp.cs ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   + CategoryInfo          : ReadError: (F:\Corporate\...e A Train & Ship:String) [Get-ChildItem], PathTooLongException
   + FullyQualifiedErrorId : DirIOError,Microsoft.PowerShell.Commands.GetChildItemCommand

Is anyone aware of a way I can export to CSV a list like this?

1
  • have you tried with the native DIR command in cmd.exe? cmd /c dir /A:A /B /S Jan 7, 2015 at 10:28

2 Answers 2

2

Robocopy is a swiss army knife with MANY options. I think all other tools will suffer from the path too long error. Do you really need all the properties that Get-ChildItem produces in the CSV, or are you only interested in a list of fully qualified file names? If the latter, try this:

ROBOCOPY source dest /IA:AO /FP /NP /S /L /LOG:myfiles.txt

/L produces a list without copying data.
/FP includes the full path instead of just the file name.
/NP suppresses % progress messages in the log
See the "file selection options" from the Robocopy usage:
/IA:[RASHCNETO] :: Include only files with any of the given Attributes set

1

Found a Powershell-based solution in this SO answer, which explains how to ignore these dreaded PathTooLongException loggings. Here's my specific use:

Get-ChildItem *.txt -Recurse -ErrorAction SilentlyContinue | Select-String "my pattern"

For OP's scenario, this would amount to:

Get-ChildItem -Attributes A+O -Recurse -ErrorAction SilentlyContinue | Export-Csv "rslt.csv"

One major downside: this silently ignores all paths that are considered "too long" for Powershell's taste (just as the command promises). However, in my own case, I merely ment to suppress these errors about node_modules folders. Others might land here with the same problem, so I decided to share here nonetheless...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .