我有一个批次的问题。它会扫描文件夹中的新pdf文件,打印,移动和删除它们。它工作正常,直到突然停止没有错误。如果我手动将其键入cmd,它会调用“文件路径不存在”,但这是正确的路径。我没有任何线索,也许有些人可以帮忙或者有同样的问题。
预先感谢您的帮助。
@echo off
:pdfprint
echo Checkin Druck - bitte offen lassen
IF EXIST *.pdf for %%p in ("C:\Users\Public\Documents\Lexware\bueroeasy\Daten\eRechnung\signed\*.pdf") do ( start /b "Print" "C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe" /n /t "%%p"
ping 127.0.0.1 -n 10
%windir%\system32\taskkill.exe /F /IM AcroRd32.exe
ping 127.0.0.1 -n 5
xcopy "C:\Users\Public\Documents\Lexware\bueroeasy\Daten\eRechnung\signed\*.pdf" "C:\Users\Textilpflege\Desktop\backup\"
ping 127.0.0.1 -n 2
move "%%p" "C:\Users\Textilpflege\Documents\Belegtransfer\9860-11206\Rechnungsausgang\"
IF EXIST *.pdf for %%p in ("C:\Users\Public\Documents\Lexware\bueroeasy\Daten\eRechnung\signed\*.pdf") do DEL *.pdf
)
IF EXIST *.pdf for %%p in ("C:\Users\Public\Documents\Lexware\bueroeasy\Daten\Poststelle\*.pdf") do ( start /b "Print" "C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe" /n /t "%%p"
ping 127.0.0.1 -n 10
%windir%\system32\taskkill.exe /F /IM AcroRd32.exe
ping 127.0.0.1 -n 5
xcopy "C:\Users\Public\Documents\Lexware\bueroeasy\Daten\Poststelle\*.pdf" "C:\Users\Textilpflege\Desktop\backup\"
ping 127.0.0.1 -n 2
move "%%p" "C:\Users\Textilpflege\Documents\Belegtransfer\9860-11206\Rechnungsausgang\"
IF EXIST *.pdf for %%p in ("C:\Users\Public\Documents\Lexware\bueroeasy\Daten\Poststelle\*.pdf") do DEL *.pdf
)
goto :pdfprint
让我通过一些更改来修改脚本。首先,我不确定为什么要检查文件是否存在于本地,然后在另一个目录上执行删除操作。另外,让我们为ping
扫出timeout
@echo off
:pdfprint
echo Checkin Druck - bitte offen lassen
for %%a in ("C:\Users\Public\Documents\Lexware\bueroeasy\Daten\eRechnung\signed\*.pdf") do (
start /b "Print" "C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe" /n /t "%%a"
timeout 10
%windir%\system32\taskkill.exe /F /IM AcroRd32.exe
timeout 5
xcopy "C:\Users\Public\Documents\Lexware\bueroeasy\Daten\eRechnung\signed\*.pdf" "C:\Users\Textilpflege\Desktop\backup\"
timeout 2
move "%%a" "C:\Users\Textilpflege\Documents\Belegtransfer\9860-11206\Rechnungsausgang\"
del "C:\Users\Public\Documents\Lexware\bueroeasy\Daten\eRechnung\signed\*.pdf"
)
for %%d in ("C:\Users\Public\Documents\Lexware\bueroeasy\Daten\Poststelle\*.pdf") do (
start /b "Print" "C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe" /n /t "%%d"
timeout 5
%windir%\system32\taskkill.exe /F /IM AcroRd32.exe
timeout 5
xcopy "C:\Users\Public\Documents\Lexware\bueroeasy\Daten\Poststelle\*.pdf" "C:\Users\Textilpflege\Desktop\backup\"
timeout 2
move "%%d" "C:\Users\Textilpflege\Documents\Belegtransfer\9860-11206\Rechnungsausgang\"
del "C:\Users\Public\Documents\Lexware\bueroeasy\Daten\Poststelle\*.pdf"
)
goto :pdfprint
问题!
for %%p in (path\to\*.pdf) del *.pdf
如此有效地说,对于每个pdf
,删除所有pdf
的。只需做一个没有不需要的for循环的del path\*.pdf
。%%p
分配给2 for循环,相反,我添加了%%a
和%%d