I'm afraid you can't.
EnumerateFiles doesn't load the whole list of results in memory: you can enumerate results before the end of the search.
However, it'll always ask for permissions on the directory currently being searched before returning any result for that specific directory. This means it'll throw the exception before the
Where clause is checked.
As a side note, not only
Recycle Bin will throw an exception, but all other directories the user that run your process doesn't have access to.
You should go for the solution you found that enumerates files and directories separately (with a try/catch).
- EnumerateFiles in drive using LINQ to skip Recycle Bin
- Convert string to int in one line of code using LINQ
- Using Linq to sum up to a number (and skip the rest)
- PagedList using LINQ Skip and Take, but show paging using Count of results
- Left outer join using LINQ -- understanding the code
- How to reuse a linq expression for 'Where' when using multiple source tables
- Avoiding code repetition when using LINQ
- Using LINQ to delete an element from a ObservableCollection Source
- LINQ Source Code Available
- Is it possible to ignore a list item using the Skip method of the LINQ then apply skip on the list without losing that item?
- How can I write the following code more elegantly using LINQ query syntax?
- How can I code an outer join using LINQ and EF6?
- C# .Net 3.5 Code to replace a file extension using LINQ
- Trying to understand LINQ code using c#
- Retrieve bool result by using LinQ code
- creating Linq to sqlite dbml from DbLinq source code
- read icollection data using LINQ in C# code
- Linq sub query when using a repository pattern with EF code first
- Using LINQ query result for data source for GridControl c#
- How to flatten a multi level XML into a single level XML using c# code LINQ
- Using Linq to build a graph class; can you make this code look better?
- How to write this code using the Linq Extension Method-Syntax?
- Code Rewite for tuple and if else statements by using LINQ
- How can I check the number of calls to the database in LINQ query when using .NET Core and Code First?
- Can't add a new record with an integer value into database by using linq from code C#
- How to simplify the code Using LINQ
- The source contains no DataRows using Linq
- Rewriting code using LINQ
- Using only Linq or Lambda, how do I combine both pieces of code to return List<Entity> e?
- How to handle nulls in this LINQ Code using a possible null List?
- Get null for empty collection in LINQ Group
- Get value from expression in linq extension method
- how do you split up or join a linq query on an "or" (without using Union)?
- How to express VB .NET "Aggregate Into" in C#?
- Linq Group by relative entites
- Extracting table using Htmlagilitypack + LINQ + Lambda
- Using LINQ find nearby places from database
- GroupBy two long type
- How can I control all of these situations that I want to find no reservation at that selected checkin and checkout time?
- Conditional join between a list and a datatable on linq
- LINQ: Cannot insert duplicate key row in object 'dbo.tblOutstandingCompletions' with unique index
- LINQ nested grouping with multiple collections
- LINQ case insensitive
- How and I introduce an "or" operator into a linq query join
- Need LINQ query to search a list of string in a list of input values
- How to join a one-to-many relationship in Entity Framework?
- Modify linq query how to?
- LINQ multiple Joins with a Group By
- Any() linq query on XmlNodeList
- Compare two List<T> using LINQ