If exist does not work anymore in a batch file

If exist does not work anymore in a batch file



i have a problem with a batch. It scans folders for new pdf files, print, move and delete them. It worked fine until it suddenly stopped without an error. If i type it manually into the cmd it calls "file path does not exist", but it's the correct path. I don't have any clue, maybe some can help or have the same issue.



Thank you in advance for your help.


@echo off

:pdfprint

echo Checkin Druck - bitte offen lassen

IF EXIST *.pdf for %%p in ("C:UsersPublicDocumentsLexwarebueroeasyDateneRechnungsigned*.pdf") do ( start /b "Print" "C:Program Files (x86)AdobeAcrobat Reader DCReaderAcroRd32.exe" /n /t "%%p"

ping 127.0.0.1 -n 10

%windir%system32taskkill.exe /F /IM AcroRd32.exe

ping 127.0.0.1 -n 5

xcopy "C:UsersPublicDocumentsLexwarebueroeasyDateneRechnungsigned*.pdf" "C:UsersTextilpflegeDesktopbackup"
ping 127.0.0.1 -n 2
move "%%p" "C:UsersTextilpflegeDocumentsBelegtransfer9860-11206Rechnungsausgang"
IF EXIST *.pdf for %%p in ("C:UsersPublicDocumentsLexwarebueroeasyDateneRechnungsigned*.pdf") do DEL *.pdf

)
IF EXIST *.pdf for %%p in ("C:UsersPublicDocumentsLexwarebueroeasyDatenPoststelle*.pdf") do ( start /b "Print" "C:Program Files (x86)AdobeAcrobat Reader DCReaderAcroRd32.exe" /n /t "%%p"

ping 127.0.0.1 -n 10

%windir%system32taskkill.exe /F /IM AcroRd32.exe

ping 127.0.0.1 -n 5
xcopy "C:UsersPublicDocumentsLexwarebueroeasyDatenPoststelle*.pdf" "C:UsersTextilpflegeDesktopbackup"
ping 127.0.0.1 -n 2
move "%%p" "C:UsersTextilpflegeDocumentsBelegtransfer9860-11206Rechnungsausgang"
IF EXIST *.pdf for %%p in ("C:UsersPublicDocumentsLexwarebueroeasyDatenPoststelle*.pdf") do DEL *.pdf

)

goto :pdfprint






remove @echo off and launch the file from cmd.exe and simply see which path fails.

– Gerhard Barnard
Sep 10 '18 at 12:07



@echo off






remove @echo off as Gerhard says. Also add echo commands throughout like echo step1 , echo step2 in order to see where if fails.

– Menelaos Bakopoulos
Sep 10 '18 at 12:10


echo step1


echo step2






@MenelaosBakopoulos why bother adding more echo's? Just remove @echo off run the file and it will give the error directly after the failing path.

– Gerhard Barnard
Sep 10 '18 at 12:12



@echo off






thank you for your comment. It's ridiculous, no path fails, runs through properly. It just don't print, move, copy the file

– Dario Buchholz
Sep 10 '18 at 12:13







You not need the IF EXIST *.pdf command at all. The for %%p in ("...*.pdf") one process existent files. If files not exists, process nothing...

– Aacini
Sep 10 '18 at 12:27


IF EXIST *.pdf


for %%p in ("...*.pdf")




1 Answer
1



Let me modify the script with some changes. Firstly, I am unsure of why you want to check if files exist locally, then do a for delete on another dir. Also, let's swop out ping for timeout


ping


timeout


@echo off
:pdfprint
echo Checkin Druck - bitte offen lassen

for %%a in ("C:UsersPublicDocumentsLexwarebueroeasyDateneRechnungsigned*.pdf") do (
start /b "Print" "C:Program Files (x86)AdobeAcrobat Reader DCReaderAcroRd32.exe" /n /t "%%a"
timeout 10
%windir%system32taskkill.exe /F /IM AcroRd32.exe
timeout 5
xcopy "C:UsersPublicDocumentsLexwarebueroeasyDateneRechnungsigned*.pdf" "C:UsersTextilpflegeDesktopbackup"
timeout 2
move "%%a" "C:UsersTextilpflegeDocumentsBelegtransfer9860-11206Rechnungsausgang"
del "C:UsersPublicDocumentsLexwarebueroeasyDateneRechnungsigned*.pdf"
)
for %%d in ("C:UsersPublicDocumentsLexwarebueroeasyDatenPoststelle*.pdf") do (
start /b "Print" "C:Program Files (x86)AdobeAcrobat Reader DCReaderAcroRd32.exe" /n /t "%%d"
timeout 5
%windir%system32taskkill.exe /F /IM AcroRd32.exe
timeout 5
xcopy "C:UsersPublicDocumentsLexwarebueroeasyDatenPoststelle*.pdf" "C:UsersTextilpflegeDesktopbackup"
timeout 2
move "%%d" "C:UsersTextilpflegeDocumentsBelegtransfer9860-11206Rechnungsausgang"
del "C:UsersPublicDocumentsLexwarebueroeasyDatenPoststelle*.pdf"
)
goto :pdfprint



Problems!



too many for loops where not needed. You do for %%p in (pathto*.pdf) del *.pdf so effectively saying, for each pdf, delete all pdf's. Simply do a del path*.pdf without the unwanted for loops.


for %%p in (pathto*.pdf) del *.pdf


pdf


pdf


del path*.pdf



You assign the same token value %%p to 2 for loops, instead, I added %%a and %%d


%%p


%%a


%%d



The if exist statements are useless, as you check if exist locally *.pdf, but delete in another folder.






for %%p in ("C:UsersPublicDocumentsLexwarebueroeasyDateneRechnungsigned*.pdf") do ( start /b "Print" "C:Program Files (x86)AdobeAcrobat Reader DCReaderAcroRd32.exe" /n /t "%%p" "%%p" can not be processed syntactically at this point.

– Dario Buchholz
Sep 10 '18 at 12:51






Because in this folder the pdf appear as soon as they are created, they should not be stored there because they have to be further processed

– Dario Buchholz
Sep 10 '18 at 12:54






signed and Poststelle are folders

– Dario Buchholz
Sep 10 '18 at 12:56







i don't know why but after signed there is a slash. If i write a comment here it disappear

– Dario Buchholz
Sep 10 '18 at 12:57







it's working now. Great thanks. Is the query necessary? What the heck was the problem?

– Dario Buchholz
Sep 10 '18 at 13:06




Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế