我想将一些PDF与pdftk合并。 要将pdfs与pdftk合并,您必须使用
#!/bin/bash
for file in *_KM_1
do
number=$( echo $file | cut -d'_' -f1 )
files=$(ls | grep "$number")
echo "Found Number: $number"
pdftk $files output output/$number.pdf
echo "Wrote merged file to: /output/$number.pdf"
done
但我必须将很多pdfs与像这样的文件名合并
BOOST_ROOT
批处理脚本应解析文件名并合并所有以相同文件名开头的文件,如BCCM995_ * oder QREM657 _ *。
" _"是分隔符。
我有一个带有这个功能的bash脚本,但我需要一个批处理脚本。
lib
有人可以帮助我或推荐我一个网站来学习批处理吗?
由于
答案 0 :(得分:0)
虽然我以前不回答至少没有提供一小部分批处理文件代码的问题,但在这种情况下我做了例外......
@echo off
setlocal EnableDelayedExpansion
rem Initialize (delete) "lastFile" and "fileList" variables
set "lastFile="
set "fileList="
rem Next line get the output of a "dir /B" command, that show file names *only*
rem "for /F" command execute the dir, get the output and divide each line in two "tokens" ("%%a" and "%%b")
rem with the first part before the "_" in "%%a" and the *rest* (including further "_") in "%%b"
for /F "tokens=1* delims=_" %%a in ('dir /B *_KM_*.*') do (
rem If the base file name changed...
if "%%a" neq "!lastFile!" (
rem Process previous file list;
rem this "if" is just to avoid process the empty list the first time
if defined fileList (
pdftk !fileList! output !lastFile!.pdf
)
rem Reinitialize the new list
set "lastFile=%%a"
set "fileList=%%a_%%b"
) else (
rem Append this file to current list
set "fileList=!fileList! %%a_%%b"
)
)
rem Process the last list
pdftk !fileList! output !lastFile!.pdf
有关任何命令的更多详细信息,请键入help
,后跟命令名称,或键入带/?
参数的命令;例如:for /?
。特别是,你应该寻找"延迟扩展"这个论坛上的问题......