Click here to Skip to main content
15,886,797 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I am trying to get the number of files copied value from a logfile produce by a RoboCopy method within my application. The logfile is always in this format:

-------------------------------------------------------------------------------
ROBOCOPY :: Robust File Copy for Windows :: Version XP010
-------------------------------------------------------------------------------

Started : Thu Oct 10 10:08:51 2013

Source : \\ad\nas\Dev_Code\ITA\Stats\11.6.4.15\CFI\Build\
Dest : C:\inetpub\CFI\

Files : *.*

Options : *.* /FFT /NFL /TEE /S /E /COPY:DAT /Z /IS /R:5 /W:5

------------------------------------------------------------------------------

1 \\ad\nas\Dev_Code\ITA\Stats\11.6.4.15\CFI\Build\

------------------------------------------------------------------------------

Total Copied Skipped Mismatch FAILED Extras
Dirs : 1 0 1 0 0 0
Files : 1 1 0 0 0 0
Bytes : 1.62 m 1.62 m 0 0 0 0
Times : 0:00:03 0:00:02 0:00:00 0:00:00

Speed : 607364 Bytes/sec.
Speed : 34.753 MegaBytes/min.

Ended : Thu Oct 10 10:08:59 2013


So far I am able to read the file into a streamreader but is there anything I can do to ensure I am always selecting the last instance of Files : and then the value under the Total column i.e. 1. Below I am trying to split the string based on it being tab delimited but this is returning System.String[]

C#
try
{
// Open file for reading.
using (StreamReader r = new StreamReader(@"C:\LogFile.log"))
{
    // 2.
    // Read each line until EOF.
    string line;
    while ((line = r.ReadLine()) != null)
    {
        // 3.
        // Do stuff with line.
        if (line.Contains("Files"))
        {
            String content = line.ToString();
            char sep = '\t';
            string[] splitContent = content.Split(sep);
            Console.WriteLine(splitContent);
        }
    }
}
}
catch (Exception)
{

throw;
}
Posted

Output your array of strings like this:
C#
foreach (string s in splitContent)
  Console.WriteLine(s)
 
Share this answer
 
Comments
pmcm 17-Oct-13 6:58am    
just tested this and I don't believe my code is creating an array based on content.Split(sep); because during debugging whenever I verify splitContent I have 1 string =
[0] = " Files : 1 1 0 0 0 0"

Any idea how I should best split this line to pull the 1st value after " Files :"??
If \t doesn't work, could it be there are spaces? Try this:




C#
splitcontent = System.Text.RegularExpressions.Regex.Replace(content, @"\s+"," ").Split(' ');


It replaces all spaces with a single one and then splits the string
 
Share this answer
 
Comments
pmcm 17-Oct-13 8:41am    
Thank you for your help!
here's my full working example:
C#
static void Main()
        {
            try
            {              
                // Open file for reading.
                using (StreamReader r = new StreamReader(@"C:\LogFile.log"))
                {
                    // 2.
                    // Read each line until EOF.
                    string line;
                    while ((line = r.ReadLine()) != null)
                    {
                        // 3.
                        // Do stuff with line.
                        if (line.Contains("Files"))
                        {
                            if (!line.Contains("Files : *.*"))
                            {
                                String content = line.ToString();

                                string[] splitContent = System.Text.RegularExpressions.Regex.Replace(content, @"\s+", " ").Split(' ');

                                //foreach (string s in splitContent)
                                //Console.WriteLine(s);
                                Console.WriteLine(splitContent[3]);
                            }                           
                        }                        
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900