在Windows脚本中的目录文件中操作
我想创建一个脚本,用Libreoffice将ODT转换为PDF,因此我创建了以下脚本:在Windows脚本中的目录文件中操作,windows,batch-file,command-line,Windows,Batch File,Command Line,我想创建一个脚本,用Libreoffice将ODT转换为PDF,因此我创建了以下脚本: @echo off for %%f in (*.odt) do ( soffice.exe --headless --convert-to pdf "%%~nf.odt" ) 但这很慢,因为它可以创建许多进程。因此,我想做以下工作: soffice.exe --headless --convert-to pdf file1 file2 file3 .... filen 并通过命令调
@echo off
for %%f in (*.odt) do (
soffice.exe --headless --convert-to pdf "%%~nf.odt"
)
但这很慢,因为它可以创建许多进程。因此,我想做以下工作:
soffice.exe --headless --convert-to pdf file1 file2 file3 .... filen
并通过命令调用处理所有文件。首先构建文件列表,然后调用转换器:
@echo off
setlocal enabledelayedexpansion
set filelist=
for %%f in (*.odt) do (
set "filelist=!filelist! "%%~nf.odt""
)
soffice.exe --headless --convert-to pdf %filelist%
谢谢,这正是我想要的。@arcad,如果您有许多文件要转换,这可能会失败,因为在执行cmd.Hmm之前,您的行长度限制为8192。理论上,该代码一次只能转换一个文件。一次只能运行一个进程。不,它可以工作。我已经试过了。然后我会尝试使用带有
/WAIT
选项的START
命令,或者在启动soffice.exe时使用CALL
命令。