Windows If exist不再在批处理文件中工作

Windows If exist不再在批处理文件中工作,windows,batch-file,if-statement,cmd,exists,Windows,Batch File,If Statement,Cmd,Exists,我有一批货的问题。它扫描文件夹中的新pdf文件,打印、移动和删除它们。它工作得很好,直到它突然停止而没有出现错误。如果我在cmd中手动输入它,它会调用“文件路径不存在”,但它是正确的路径。我没有任何线索,也许有些人可以帮忙,或者有同样的问题 提前感谢您的帮助 @echo off :pdfprint echo Checkin Druck - bitte offen lassen IF EXIST *.pdf for %%p in ("C:\Users\Public\Documents\Lex

我有一批货的问题。它扫描文件夹中的新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
for
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
问题

  • 对于不需要的循环太多。对于%%p(path\to\*.pdf)del*.pdf中的
    ,您可以有效地说,对于每个
    pdf
    ,删除所有
    pdf
    。只需执行一个
    delpath\*.pdf
    ,而不需要任何for循环

  • 对于循环,您将相同的令牌值
    %%p
    分配给2,而我添加了
    %%a
    %%d

  • if-exist语句是无用的,因为您会检查if-exist local*.pdf,但会在另一个文件夹中删除


  • 删除
    @echo-off
    并从cmd.exe启动文件,只需查看哪个路径失败。删除@echo-off,如Gerhard所说。还要在整个过程中添加echo命令,如
    echo step1
    echo step2
    ,以查看if失败的地方。@MenelaosBakopoulos为什么还要添加更多echo?只需删除
    @echo off
    运行该文件,它将在路径失败后直接给出错误。感谢您的评论。这太荒谬了,没有一条路会失败,正确地通过。它只是不打印、移动、复制文件,根本不需要
    IF EXIST*.pdf
    命令。“…\*.pdf”中%%p的
    一个进程处理现有文件。如果文件不存在,则不处理“%p”(C:\Users\Public\Documents\Lexware\bueroeasy\Daten\eRechnung\signed*.pdf”)中的%%p(开始/b“打印”C:\Program files(x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe”/n/t“%%p”“%%p”此时无法按语法处理。因为在这个文件夹中,pdf文件一创建就显示出来,不应该存储在那里,因为它们需要进一步处理签名和Poststelle都是文件夹我不知道为什么签名后会有一个斜杠。如果我在这里写评论,它就消失了。非常感谢。不是吗他有必要吗?到底是什么问题?