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 7871163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:49:33+00:00 2026-06-03T01:49:33+00:00

I currently have a program where I am taking existing log files from a

  • 0

I currently have a program where I am taking existing log files from a directory, running through each one and calculating statistics, then creating a new file from that.

The log files are currently named as such: 2012-4-24.log

Upon creation of the new statistics file, it keeps similar formatting but adds “-Stats”: 2012-4-24-Stats.log

Here is what I am trying to solve: I want to create new directories for each year, and month, that way I can have a folder structure as follows:

DailyStatistics -> 2012 -> 4 -> 2012-4-24-Stats.log

DailyStatistics -> 2012 -> 5 -> 2012-5-1-Stats.log

etc, etc

I am not sure how to parse the year and month from the filename, and then run through all files with that same year and month, then have my program go through my loop to create the actual files.

Here is the code I have…

class Processor
{
    public void ProcessDailyLogFiles()
    {
        foreach (string fullFileName in Directory.GetFiles(Settings.LogPath))
        {
            string fileName = Path.GetFileNameWithoutExtension(fullFileName);
            new DailyReader().CalculateStatistics(fileName);
            new DailyReader().MoveLogFile(fileName);
        }

    }
}

next class…

public void CalculateStatistics(string filename)
    {
        string path = Settings.DailyPath;

        if (!path.EndsWith(@"\"))
            path = path + @"\";

        if (!Directory.Exists(path))
        {
            Directory.CreateDirectory(path);
        }

        string tempFileName = Settings.LogPath + filename + ".log";
        string destFileName = path + filename + "-Stats.log";

        var statistics = File.ReadLines(tempFileName)
        .Where(line => line.StartsWith("Process"))
        .Select(line => line.Split('\t'))
        .GroupBy(items => items[1])
        .Select(g =>
        new
        {
            Division = g.Key,
            ZipFiles = g.Sum(i => Convert.ToInt32(i[4])),
            Conversions = g.Sum(i => Convert.ToInt32(i[5])),
            ReturnedFiles = g.Sum(i => Convert.ToInt32(i[6])),
            TotalEmails = g.Sum(i => Convert.ToInt32(i[7]))
        });

        Log myLog = new Log(destFileName);
        statistics
           .ToList()
           .ForEach(d => myLog.Write(d.Division, d.ZipFiles, d.Conversions, d.ReturnedFiles, d.TotalEmails));
        //Add error handlers
        myLog.Close();
    }

final log class…

#region Member Variables

    StreamWriter dailyStats;

    #endregion

    public Log(string filename)
    {
        this.Open(filename);
    }

    #region Public Static Functions

    public void Open(string tempFileName)
    {
        var sb = new StringBuilder();

        if (!File.Exists(tempFileName))
        {
            dailyStats = File.AppendText(tempFileName);
            sb.Append("Division");
            sb.Append("\t");
            sb.Append("Zip Files");
            sb.Append("\t");
            sb.Append("Conversions");
            sb.Append("\t");
            sb.Append("Returned Files");
            sb.Append("\t");
            sb.Append("Total E-Mails");
            sb.Append("\t");
            dailyStats.WriteLine(sb.ToString());
        }
        else
        {
            dailyStats = new StreamWriter(tempFileName);
        }
    }


    public void Write(string division,
                             int zipFiles, int conversions, int returnedFiles, int totalEmails)
    {

        var sb = new StringBuilder();

        if (writeLog)
        {
            sb.Append(division);
            sb.Append("\t");
            sb.Append(zipFiles);
            sb.Append("\t");
            sb.Append(conversions);
            sb.Append("\t");
            sb.Append(returnedFiles);
            sb.Append("\t");
            sb.Append(totalEmails);
            sb.Append("\t");
            dailyStats.WriteLine(sb.ToString());
        }
    }

    public void Close()
    { 
        dailyStats.Close();
    }
}

Thanks guys

  • 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-03T01:49:35+00:00Added an answer on June 3, 2026 at 1:49 am
      String filename = "2012-4-24.log";
      String file = Path.GetFileNameWithoutExtension(filename);
      String[] parts = file.Split('-');
      if (parts.Length == 3)
      {
        String year = parts[0];
        String month = parts[1];
        String day = parts[2];
    
        Console.WriteLine(string.Format("year:{0} - month:{1} - day:{2}", year, month, day));
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have two threads running in my program: Main thread - Grabs image
We have an app that currently installs itself into 'program files\our app', and it
I currently have 2 virtual machines running, one is a server and one is
I currently have a basic chat program in c++ that uses WinSock2.h with UDP.
I have a python program that I am currently working on which is working
Say I have a command line C program which is currently executing, and I
I'm currently just starting my first Lua program and I have a .csv file
I am currently trying to build a program where I have a recursive function
I have a cd , dvd. book media program. Currently, i am trying to
I have a Ruby program that loads up two very large yaml files, so

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.