如果存在在批处理文件中不再起作用
If exist does not work anymore in a batch file
我有一批问题。它扫描文件夹中的新 pdf 文件,打印、移动和删除它们。它工作正常,直到它突然停止而没有错误。如果我将其手动输入到 cmd 中,它会调用 "file path does not exist",但这是正确的路径。我没有任何线索,也许有人可以提供帮助或遇到同样的问题。
预先感谢您的帮助。
@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\Belegtransfer60-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\Belegtransfer60-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\Belegtransfer60-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\Belegtransfer60-11206\Rechnungsausgang\"
del "C:\Users\Public\Documents\Lexware\bueroeasy\Daten\Poststelle\*.pdf"
)
goto :pdfprint
问题!
太多不需要的循环。您 for %%p in (path\to\*.pdf) del *.pdf
如此有效地说,对于每个 pdf
,删除所有 pdf
。简单地做一个 del path\*.pdf
没有不需要的 for 循环。
您将相同的标记值 %%p
分配给 2 个 for 循环,相反,我添加了 %%a
和 %%d
if exist语句没有用,因为你检查本地是否存在*.pdf,但在另一个文件夹中删除。
我有一批问题。它扫描文件夹中的新 pdf 文件,打印、移动和删除它们。它工作正常,直到它突然停止而没有错误。如果我将其手动输入到 cmd 中,它会调用 "file path does not exist",但这是正确的路径。我没有任何线索,也许有人可以提供帮助或遇到同样的问题。
预先感谢您的帮助。
@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\Belegtransfer60-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\Belegtransfer60-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\Belegtransfer60-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\Belegtransfer60-11206\Rechnungsausgang\"
del "C:\Users\Public\Documents\Lexware\bueroeasy\Daten\Poststelle\*.pdf"
)
goto :pdfprint
问题!
太多不需要的循环。您
for %%p in (path\to\*.pdf) del *.pdf
如此有效地说,对于每个pdf
,删除所有pdf
。简单地做一个del path\*.pdf
没有不需要的 for 循环。您将相同的标记值
%%p
分配给 2 个 for 循环,相反,我添加了%%a
和%%d
if exist语句没有用,因为你检查本地是否存在*.pdf,但在另一个文件夹中删除。