1.

Solve : execute a batch file only if PDF exists?

Answer»

We have a function where our Field personnel send our server a PDF of a customer's invoice and a CSV file that is imported into our main server VIA Google Drive. When our server gets the CSV it then creates a Command line emailer batch file that will E-Mail our customer and Attach the PDF.

This works fine about 95% of the time Occasionally, however, the PDF gets delayed in Google Drive and the Batch file gets to the "BlatSend" directory before the PDF gets there. Since the Batch file is set to move itself to the "BlatSent" directory after execution, we end up later with the PDF still sitting in the "BlatSend directory and the customer never gets E-Mailed.

Here is the LOOP-EM.bat Batch file that runs every 30 seconds to execute any Batch files in the BlatSend directory.
================= Loop-EM.bat ====================================
echo off
cls
c:
echo . C:\Blat\Loop-EM.bat
echo .
echo . Must run in Windows 7 Machine that can see the internet
echo .
echo . Executes Every C:\qaloopshre\BlatSend\xxxxxxx.bat file
echo .
echo . (This is the same directory called E: by the Virtual)
echo .
echo . and moves the files to BlatSent Delay is 30 Seconds
echo .
time /T
echo .
cd\qaloopshare\blatsend
for /r C:\qaloopshare\blatsend\ %%W in (*.bat) do call %%W

rem for /r C:\qaloopshare\blatsend\ %%W in (*.pdf) do call %%W (.bat)

CHOICE /C YN /T 30 /D Y /M "Select Y to continue loop or N to stop loop"
IF ERRORLEVEL 2 GOTO Stop
IF ERRORLEVEL 1 GOTO Loop
:Stop
EXIT
:Loop
C:\BLAT\LOOP-EM.BAT
===============================================================


Here is an example of ONE of the Work Order Batch files. This one would be named 2489148.Bat and would be accompanied by 2489148.PDF. Swithmail is just a command line emailer program.

================ 2489148.bat =======================================

set WO#=2489148
set [emailprotected]
c:\
cd\swithmail
set from=/from "[emailprotected]"
set fromname=/name "MY Name"
set pass=/pass "MyPassword"
set server=/server "smtp.gmail.com" /p "587" /SSL
set subject=/sub "Work Order %WO#% from MyCompany"
set attach=/a "c:\qaloopshare\blatsend\%WO#%.pdf"
set body=/btxt "c:\swithmail\Body-WO.txt"
call swithmail.exe /s %from% %fromname% %pass% %server% /to "%to%" %subject% %attach% %body%
move c:\qaloopshare\blatsend\%WO#%.pdf c:\qaloopshare\blatsent
move c:\qaloopshare\blatsend\%WO#%.bat c:\qaloopshare\blatsent

=================================================================

Please keep in mind that there may be several batch files show up at the same time. Of course, each will have it's unique name.

Possible solution

It seems to me that it should be very simple to simply write a for command that will only execute the batch file if the corresponding PDF EXISTS. I tried this in the LOOP-EM.Bat. My attempt is remmed out right above the CHOICE command.

If you see my syntax error or have a totally different way of approaching this please let me know or ask me to clarify.

Thanks in advance for your help.

Mike WeberWhat about increasing the delay to like 45 sec or 60 sec instead, so your giving it more time to populate the files before processing?

My thoughts are that if the pdf is a larger file and the network is PRETTY busy, it doesnt have enough delay time to process it.Code: [Select] IF EXIST "X:\path\filename.pdf" call :labelDave.
Thanks, but the time delay is irrelevant because the problem concours when the file comes in just before the time delay ends

Thanks for suggestion
Squashman

Thanks for. IF EXIST "X:\path\filename.pdf" call :label

I'm not sure how to write that into my for statement

for /r C:\qaloopshare\blatsend\ %%W in (*.pdf) do call %%W (.bat)


Thanks

Mike


I got it going.
I actually added th exist statement to the template that makes the individual work order batch files
Swithmail will not execute if a called for ATTACHMENT does not exist so all I did was to put the exist statement in front of the move statements. Then the batch file runs each time around, but accomplishes nothing until the PDF shows up.


call swithmail.exe /s %from% %fromname% %pass% %server% /to "%to%" %subject% %attach% %body%

If exist c:\qaloopshare\blatsend\%WO#%.pdf (

move c:\qaloopshare\blatsend\%WO#%.pdf c:\qaloopshare\blatsent
move c:\qaloopshare\blatsend\%WO#%.bat c:\qaloopshare\blatsent
)

Thanks

Mike



Discussion

No Comment Found