batch-file - 如何从 .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
解决方案
推荐阅读
- react-native-android - 如何在 react-native-navigation V2 中为 Android 实现 hideOnScroll?
- python - 根据两列的组合过滤 Pandas 数据框
- php - PHP中的嵌套数据集结构
- python - Telethon Python asyncio TypeError:“协程”对象不可调用
- c# - 如何解释 VS 资源的 URI 字符串
- reactjs - ReactJS 与 Tabs 一起使用时无法更新状态
- jwt - 如何仅从 jwt 编码的令牌中获取令牌
- javascript - 降价到 html javascript
- sql - sql更新多行,每行都有条件
- java - 如何为使用 JWT (JWS) 进行身份验证的 ActiveMQ (for MQTT) 创建身份验证插件 (interceptop)?