Abstract ToBeTranslated and Updated words from LocStudio statistic files

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");

        }
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值