Advertisement

06.09.2008 at 08:18PM PDT, ID: 23471174
[x]
Attachment Details

Efficient use of LINQ to FileInfo objects

Asked by Dabas in Language Integrated Query - LINQ, Microsoft Visual C#.Net, .NET Framework 3.x versions

Tags: C# .NET 3.5

I have a folder with a very large quantity of files in it.
I have written a small console application as per the code snippet using LINQ to Objects

My aim is to count the amount of files in the folder that are between two given dates
Unfortunately, LINQ does not seem to be very efficient, as it still tries to enumerate through all of the files in the folder, even though I am trying to aid its work by sorting the collection and filtering it by creation date.

Is there a way to make this code more efficient?Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
class Program
    {
        static void Main(string[] args)
        {
            DateTime FromDate = DateTime.Parse(args[0]);
            DateTime ToDate = DateTime.Parse(args[1]);
 
            GetStatistics(FromDate,ToDate); 
        }
 
        private static void GetStatistics(DateTime FromDate, DateTime ToDate)
        {
            string Location = ConfigurationManager.AppSettings["InboxLocation"];
            DirectoryInfo diInbox = new DirectoryInfo(Location);
            FileInfo[] InboxFiles = diInbox.GetFiles();
            var files = from file in InboxFiles
                        where file.CreationTime >= FromDate //&& file.CreationTime <= ToDate
                        orderby file.CreationTime descending
                        select file;
            int count = files.Count();
            Console.WriteLine("Inbox Count: {0}", count);
            Console.ReadLine();
        }
    }
[+][-]06.09.2008 at 10:54PM PDT, ID: 21748757

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Language Integrated Query - LINQ, Microsoft Visual C#.Net, .NET Framework 3.x versions
Tags: C# .NET 3.5
Sign Up Now!
Solution Provided By: cottsak
Participating Experts: 2
Solution Grade: A
 
 
[+][-]06.10.2008 at 03:32AM PDT, ID: 21749838

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.10.2008 at 03:37AM PDT, ID: 21749858

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.10.2008 at 03:39AM PDT, ID: 21749869

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.10.2008 at 03:48PM PDT, ID: 21755703

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.10.2008 at 05:11PM PDT, ID: 21755986

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.10.2008 at 05:26PM PDT, ID: 21756028

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.10.2008 at 05:37PM PDT, ID: 21756069

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.10.2008 at 05:53PM PDT, ID: 21756113

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.10.2008 at 06:28PM PDT, ID: 21756203

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.10.2008 at 06:38PM PDT, ID: 21756232

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.10.2008 at 06:58PM PDT, ID: 21756305

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.10.2008 at 07:13PM PDT, ID: 21756341

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.19.2008 at 03:22PM PDT, ID: 21827016

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.19.2008 at 06:20PM PDT, ID: 21827767

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.19.2008 at 06:40PM PDT, ID: 21827862

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.24.2008 at 11:20PM PDT, ID: 21863001

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.25.2008 at 12:44AM PDT, ID: 21863368

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.06.2008 at 02:08PM PDT, ID: 21941644

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628