Abstract ToBeTranslated and Updated words from LocStudio statistic files

来源:互联网 发布:网络暴力事例袁姗姗 编辑:程序博客网 时间:2024/04/30 12:30

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WordCount
{
    class Program
    {
        static int Main(string[] args)
        {
            //Console.WriteLine("Number of command line parameters = {0}", args.Length);
            if (args.Length == 0)
            {
                Console.WriteLine("Please enter the folder that contians the statistic csv files./r/ne.g. WordCount.exe C://DailyDrop//04222011/r/nPress any key to continue...");
                Console.ReadKey();
                return 1;
            }
            else
            {
                string startFolder = args[0];
                //string tableTitle = "File Name,Type,All,With Strings,Do Not Localize,New, Uploaded,AutoTranslated (100%),AutoTranslated Fuzzy,Copied,Previous Version,Pseudo Localized,Machine Translated,To Be Translated,Not Localized,Localized,Failed,Updated,Added Words,Deleted Words,Modified Words,Update Effort,Punctuation Only, Hotkey Only,AutoTranslated For Review,Postponed,Won't Fix,Size May Have Changed,Image May Have Changed";
                System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(startFolder);
                IEnumerable<System.IO.FileInfo> fileList = dir.GetFiles("*.*", System.IO.SearchOption.AllDirectories);
                IEnumerable<System.IO.FileInfo> fileQuery =
                    from file in fileList
                    where file.Extension == ".csv"
                    //orderby file.Name
                    select file;

                string fileName = "Total_Statistics.csv";
                System.IO.File.Delete(fileName);
                System.IO.File.AppendAllText(fileName, "lsProj Name," + "File Name," + "To Be Translated," + "Updated," + "Total/r/n");
                foreach (System.IO.FileInfo fi in fileQuery)
                {
                    string[] lines = System.IO.File.ReadAllLines(fi.FullName);
                    Console.WriteLine(fi.FullName);
                    string lsproj = fi.FullName;
                    //System.IO.File.AppendAllText(fileName, lsproj + ", " + ", " + ", " + "/r/n");
                    CountWord(lines, fileName);
                    RF(lsproj, fileName);
                }
                Console.WriteLine("Total_Statistics.csv written to disk. Press any key to exit");
                Console.ReadKey();
                return 0;
            }
        }

        static void CountWord(IEnumerable<string> csvF, string fn)
        {
            IEnumerable<string> query =
                from line in csvF
                let x = line.Split(',')
                where x.Contains("Words") && x[0] != "'TOTAL'"
                select x[1] + ", " + x[0] + ", " + x[13] + ", " + x[17];
            System.IO.File.AppendAllLines("tmp.txt", query.ToArray());
        }

        static void RF(string ls, string fn)
        {
            string[] tmpF = System.IO.File.ReadAllLines(@"tmp.txt");
            var subqu = from subline in tmpF
                          let n = subline.Split(',')
                        select ls + "," + n[1] + "," + n[2] + "," + n[3] + "," + ("=" + n[2] + "+" + n[3]);
            System.IO.File.AppendAllLines(fn, subqu.ToArray());
            System.IO.File.Delete("tmp.txt");

        }
    }
}

原创粉丝点击