dotnet-Snippets.com
Snippets: 57 | Registered User: 25 | Visitors online: 10
Main Menu

Home
Random Snippet
FAQs
Contact Us
Imprint
RSS Feeds

Rss All languages
Rss C#
Rss VB.NET
Rss C++
Rss J#
Rss ASP.NET
Google Ads

Sri Lanka .NET 
                Forum Member
Searching for files using LINQ

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

Views: 840

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 wrtite 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!