我正在尝试从.ps文件目录中获取页数,然后将该数字记录到批处理文件中。然后将页面总数添加到变量中。并且还列出了有多少页面计数为1的页面,然后列出了页面计数为2的数字,依此类推,直到1000页。
我还没有开始为“将页面总数添加到变量中。还列出有多少页面计数为1,然后是页面计数为2,以此类推,直到1000页”进行编程。现在,我只是想让循环起作用,以将目录中每个postscript文件的页码记录到文本文件中。
我无法在循环中设置变量。 我想我需要使用!而不是%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