Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7849335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:29:07+00:00 2026-06-02T18:29:07+00:00

This is a similar question I asked earlier, except different in the fact that

  • 0

This is a similar question I asked earlier, except different in the fact that I am taking multiple files and calculating the total sums off of those files. I have it to the point where I am reading all the files from a specific directory, but for some reason its not grouping correctly.

Here is the code that I have:

public void CalculateMonthlyStatistics(string monthlyFiles)
        {
            string monthlyFileName = monthlyFiles + ".log";

            var statistics = File.ReadLines(monthlyFileName)

            .GroupBy(items => items[0])
            .Select(g =>
            new
            {

                Division = g.Key,
                ZipFiles = g.Sum(i => Convert.ToInt32(i[1])),
                Conversions = g.Sum(i => Convert.ToInt32(i[2])),
                ReturnedFiles = g.Sum(i => Convert.ToInt32(i[3])),
                TotalEmails = g.Sum(i => Convert.ToInt32(i[4]))
            });

            statistics
               .ToList()
               .ForEach(d => Console.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}", 
                        d.Division, 
                        d.ZipFiles, 
                        d.Conversions, 
                        d.ReturnedFiles,  
                        d.TotalEmails));
               Console.Read();
               //.ForEach(d => Log.Open(tempFileName.TrimEnd(charsToTrim), d.Division, d.ZipFiles, d.Conversions, d.ReturnedFiles, d.TotalEmails));
        }
    }
}

The log files that I am putting into it look like the following:

 Division   Zip Files   Conversions Returned Files  Total E-Mails   
Corporate   0   5   0   5   
Energy  0   1   0   5   
Global Operations   0   3   0   3   
Oil & Gas   1   5   0   5   
Capital 5   18  0   12  

So what I am trying to do, is group by “Corporate”, “Energy”, etc. Then calculate the totals for ALL of the files being read, to create a Monthly Statistics file. I am getting totals currently, however I think its got something to do with the header that I am passing in, and I am not sure how to tell it to skip that line.

Thanks in advance

EDIT

Here is my processor, which originally reads the directory, etc.

public void ProcessMonthlyLogFiles()
    {
        DateTime currentTime = DateTime.Now;

        int month = currentTime.Month - 1;
        int year = currentTime.Year;

        string path = Path.GetDirectoryName(Settings.DailyPath + year + @"\" + month + @"\");

        foreach (string monthlyFileNames in Directory.GetFiles(path))
        {
            string monthlyFiles = path + @"\" + Path.GetFileNameWithoutExtension(monthlyFileNames);
            new MonthlyReader().CalculateMonthlyStatistics(monthlyFiles);
        }
    }

The processor finds the proper directory to search through in order to get the files from. It uses the current date, and finds last month.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T18:29:10+00:00Added an answer on June 2, 2026 at 6:29 pm

    Skipping the header is straightforward:

    File.ReadLines(monthlyFileName).Skip(1).<rest of your chain>

    However, it seems as though you’re reading one file at a time, when you want to be reading all files then calculating the statistics?

    How about first:

    public IEnumerable<String> ReadLinesInDirectory(string path)
    {
        return Directory.EnumerateFiles(path)
                        .SelectMany(f => 
                            File.ReadLines(f)
                            .AsEnumerable()
                            .Skip(1));
    }
    

    And replace ReadLines with that (ensuring you’re pointing to the right path etc).


    OK here’s the full explanation, but I think you may need to study C# some more. First, define the ReadLinesInDirectory function I wrote above.

    Then replace ProcessMonthlyLogFiles with this instead:

    public void ProcessMonthlyLogFiles()
    {
        DateTime currentTime = DateTime.Now;
    
        int month = currentTime.Month - 1;
        int year = currentTime.Year;
    
        string path = Path.GetDirectoryName(Settings.DailyPath + year + @"\" + month + @"\");
    
        CalculateMonthlyStatistics(path);
    }
    

    And in CalculateMonthlyStatistics have the first three lines (before the GroupBy) as follows:

        public void CalculateMonthlyStatistics(string path)
        {
            var statistics = ReadLinesInDirectory(path)
                             // .GroupBy etc...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is similar to a question I asked earlier . The answers to that
This question is very similar to an earlier question I asked ( This Question
This is similar to a question that has already been asked. However, I am
I asked a similar question about this previously, but I did not specify that
I have already asked a similar question earlier but I have notcied that I
I've already asked a similar question but this is slightly different so i Thought
I've kind of asked this question earlier so sorry for asking a bit similar
I asked an earlier question similar to this (with no responses), but I know
I know this sounds strange earlier I asked about similar question in one of
Guys I asked a similar question like this earlier since I was unable to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.