dotnet-Snippets.com
Add Snippet
Snippets: 136 | Registered User: 138
Main Menu

Home
Random Snippet
Contact Us
Imprint
RSS Feeds

All languages
C#
VB.NET
C++
ASP.NET
Google Ads
Searching for files using LINQ

Author: Jan Welker
Programming Language: C# Rating:
not yet rated

Views: 8512

Description:

Searching for files using LINQ

Needed Namespaces:
using System.IO;
using System.Linq;

kick it on DotNetKicks.com




C#
1
2
3
4
var files = from file in new DirectoryInfo(@"C:\").GetFiles()
            where file.Name.StartsWith("_")
            select file;



Poor Excellent
1 2 3 4 5 6 7 8 9 10
Sign in to vote for this snippet.

Comments:
(Please log in to write an comment.)

anonymous_ wrote on: 22.09.2008

This is a nice example for LINQ, but *don't* actually use it to search for files!!! This is not DLinq, which is transformed into SQL - this actually retrieves an array of _all_ the files in a directory, with all their attributes, and then performs a search in the returned array. This is *a lot* slower if the directory contains lots of files!