Exemplo n.º 1
0
        public static Int64 CountLine(String dir, String fileExt)
        {
            DirectoryChangedEventArgs args = new DirectoryChangedEventArgs();

            args.DirectoryPath = dir;

            Int64 lineCount = 0;

            // 先遍历所有文件
            string[] files;
            try
            {
                files = System.IO.Directory.GetFiles(dir);
            }
            catch (Exception ex)
            {
                args.IsOpenSuccess = false;
                args.ErrMessage    = ex.Message;
                OnDirectoryChanged?.Invoke(args);
                return(0);
            }

            args.IsOpenSuccess = true;
            OnDirectoryChanged?.Invoke(args);

            if (files != null && files.Length > 0)
            {
                foreach (string file in files)
                {
                    if (file.EndsWith(fileExt))
                    {
                        Int32 tmpCount = CountFileLine(file);
                        lineCount += tmpCount;

                        OnFileChanged?.Invoke(file, tmpCount);
                    }
                }
            }

            string[] dirs = System.IO.Directory.GetDirectories(dir);

            if (dirs != null && dir.Length > 0)
            {
                foreach (string d in dirs)
                {
                    lineCount += CountLine(d, fileExt);
                }
            }

            return(lineCount);
        }
Exemplo n.º 2
0
        private void CodeLineCounter_OnDirectoryChanged(DirectoryChangedEventArgs args)
        {
            if (args == null)
            {
                WriteDebug("目录变更参数为空!");
            }

            if (args.IsOpenSuccess)
            {
                WriteDebug("打开目录:" + args.DirectoryPath);
            }
            else
            {
                WriteDebug("目录【" + args.DirectoryPath + "】打开失败,原因:" + args.ErrMessage);
            }
        }