我正在尝试编写一个批处理文件,该文件将在目录中搜索 *.pdf 文件扩展名,然后使用 ImageMagic 将它们转换为 *.tif 文件扩展名。如果目录中有一个 PDF 文件,我可以做到这一点,但如果有多个,我不知道如何用正确的名称转换它们。问题是在循环内,fName
变量似乎没有被赋值,但在循环外,它有一个值......
这是适用于单个 PDF 文件并适用于多个文件的代码,但名称包含“.pdf”:
echo off
set dSource=C:\Users\Nick\Documents\Research\Journal Article\Figures
set fType=*.pdf
for /f "delims=" %%f in ('dir /a-d /b "%dSource%\%fType%"') do (
rem remove extension from file name, set value to variable:
set fName=%%~nf
rem call ImageMagic to convert to TIFF
rem convert -compose copy -density 300 -alpha off "%%f" "%%f.tif"
rem above line (when uncommented) lets multiple TIFF images to be produced, but they are *.pdf.tif
rem convert -compose copy -density 300 -alpha off "%fName%.pdf" "%fName%.tif"
rem above line (when uncommented) does not work because fName has no value...
rem variable value does not appear to be assigned within loop:
echo.file name within loop: %fName%
)
echo.file name after loop: %fName%
rem outside loop, variable value is now available...
rem convert -compose copy -density 300 -alpha off "%fName%.pdf" "%fName%.tif"
rem above line of code works, but only for the last file name with *.pdf discovered in directory
pause