首页 > 解决方案 > 如何从 .ps 文件中获取页数并记录它们,然后将它们全部加起来

问题描述

我正在尝试从 .ps 文件目录中获取页数,然后将该数字记录到批处理文件中。然后将总页数添加到变量中。并列出有多少页数为 1,然后页数为 2,依此类推,最多 1,000 页。

我还没有开始为“将总页数添加到变量中。并列出有多少页数为 1,然后页数为 2,依此类推,最多 1,000 页”。现在我只是想让循环工作以将目录中每个后记文件的页码记录到文本文件中。

我无法在循环中设置变量。我想我需要使用!a!而不是 %a% 但不确定如何格式化它。

我拥有的代码能够很好地将页数记录到文本文件中,直到我尝试让它循环运行然后我破坏了它。我已经根据代码下方评论中给我的建议修改了下面的代码。

@Echo On
setlocal enableDelayedExpansion
REM In the next line it sets the filename to %%f and the number of lines into %%i
for %%f in (C:\qsi\mail\vlm\5\*.ps) do for /f %%i in ('find /v /c "" ^< %%f') do (
REM The next line starts at last line and backs up 4 lines to find the line with the page count in the .ps file
set startLine=%%i
set /a startLine-=4
REM The next line records the last 4 lines to a text file
more /E +!startLine! "%%f" > temp.txt
REM The next line finds the page count on the first line of the text file and sets the page count into %%a and removes the space before the number
for /f "tokens=2 delims=:" %%a in (C:\qsi\mail\vlm\temp.txt) do set a=%%a & SET a=!a: =!
REM The next line records the page count to a text file which will contain all page counts when loop is done.
echo !a!>>count.txt
REM Next the loop starts over if there are any .ps files left to process
)
echo END Reached & pause

标签: batch-file

解决方案


推荐阅读