利用网上所说的标识统计法
保存为批处理文件,跟pdf文件放在一起运行- @echo off 2>nul 3>nul
- ::需要安装.Net Framework 2.0及以上
- ::指定父文件夹
- set "fd=E:\统计"
- if not exist "%fd%" echo;路径有误&pause&exit
- set "netpath=%systemroot%\Microsoft.NET\Framework"
- for /f "delims=" %%a in ('dir /ad /b "%netpath%\v?.*"') do (
- if exist "%netpath%\%%a\csc.exe" (
- set "cscpath=%netpath%\%%a\csc.exe"
- goto :0
- )
- )
- echo;未安装.Net Framework 2.0及以上组件或相关程序丢失&pause&exit
- :0
- >"%tmp%\$" more +20 "%~f0"
- "%cscpath%" /out:"%tmp%\$getpages.exe" "%tmp%\$"
- echo;正在统计,稍后……
- ::输出到txt文件,下句修改为 >"文本.txt" "%tmp%\$getpages.exe" "%fd%"
- "%tmp%\$getpages.exe" "%fd%"
- pause&exit
- using System;
- using System.IO;
- using System.Text.RegularExpressions;
- namespace GetPages
- {
- class PDFPageCount
- {
- static void Main(string[] args)
- {
- int i=0,s=0;
- String path = args[0].ToString();
- String[] files = Directory.GetFiles(path, "*.pdf", SearchOption.AllDirectories);
- foreach (string file in files)
- {
- FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read);
- StreamReader sr = new StreamReader(fs);
- string pdfText = sr.ReadToEnd();
- Regex regexp = new Regex(@"/Type\s*/Page[^s]");
- MatchCollection matches = regexp.Matches(pdfText);
- i++;
- s+=matches.Count;
- Console.WriteLine(file+"\t"+matches.Count);
- }
- Console.WriteLine("----------------------\r\n"+i+" Files\t"+s+" Pages");
- }
- }
- }
复制代码
|