See if file exists in Windows Folder
Printed From: Rocket Software
Category: AccuTerm Knowledge Base (read only)
Forum Name: GUI Development
Forum Description: Help for developers creating GUI applications with AccuTerm
URL: https://forum.asent.com/forum_posts.asp?TID=2268
Printed Date: March 26 2026 at 5:07pm Software Version: Web Wiz Forums 12.03 - http://www.webwizforums.com
Topic: See if file exists in Windows Folder
Posted By: homerlh
Subject: See if file exists in Windows Folder
Date Posted: March 22 2013 at 5:26am
I have an application that generates Invoices for emailing and then emails the invoices. I use something called PDF_Creator to generate the invoice and of course I use the sample program here to send email using outlook.
My problem is that I may have to rework the way I do things or else I need a better way to determine when the PDF is actually created.
I print the form to the PDF_Creator printer and it will generate the output PDF. It takes this a while to happen. Right now I have a SLEEP 2 in the program after I generate the invoice to wait until I try to send the email. Otherwise, the attachment (the PDF) cannot be found. It works with the SLEEP 2, but on my computer, it worked with a SLEEP 1. Right now I am at the client's AP computer.
I am contemplating revising the method and sending all of the invoices to the PDF generator and then trying to email all of them.
I attempted to use a script to tell me when the PDF has been created and it subsequently screws up the sending of the email. Something breaks and I don't know what. It's all commented out, but you can still probably follow the code.
* ITEM = "C:\PDF_OUTPUT\" : ID.ITEM : ".PDF"
* !
* LOOP UNTIL ANS # 0 OR TIMES < 0
* !
* PRINT ESC:STX:'PInitSession.Output CStr(Abs(FileExists("':ITEM:'"))) & Chr$(13)':CR:
* ECHO OFF; PROMPT ''
* INPUT ANS:
*! ECHO ON; PROMPT '?'
* IF ANS <= 0 THEN
* !
* EMSG = "I cannot find " : ITEM : "."
* !
* CALL ATGUISETPROP(GUIAPP,GUIFRM,"LABEL2",GPCAPTION,"","",EMSG,GUIERRORS,GUISTATE)
* IF GUIERRORS<1> >= 2 THEN GOTO GUI.ERROR
* !
* SLEEP 1
* TIMES = TIMES - 1
* END
* !
* CALL ATGUISETPROP(GUIAPP,GUIFRM,"LABEL2",GPCAPTION,"","","",GUIERRORS,GUISTATE)
* IF GUIERRORS<1> >= 2 THEN GOTO GUI.ERROR
* !
|
Can someone suggest a method to determine when the PDF has been created or am I going to have to rework the sequence of the program to PDF all and then Email all?
Thank you,
Larry Hazel
|
Replies:
Posted By: palinder
Date Posted: March 22 2013 at 8:09am
Larry:
This code should do the trick...
SUBROUTINE ACCUTERM.FILE.CHECK(PATH,STAT)
*
EQU SVM TO CHAR(252)
EQU VM TO CHAR(253)
EQU AM TO CHAR(254)
*
* Passed Parameters
*
* PATH = Full DOS Path to the file to be checked
* STAT = Result of the check
* 0 - File Not Found
* 1 - File Found
* Test if file exists using AccuTerm Script
*
STAT = 0
SCRIPT = ''
SCRIPT = 'On Error Resume Next'
SCRIPT = SCRIPT:CHAR(25):'X = 0'
SCRIPT = SCRIPT:CHAR(25):'X = Abs(FileExists("':PATH:'"))'
SCRIPT = SCRIPT:CHAR(25):'InitSession.Output Cstr(X) & Chr$(13)'
*
PRINT CHAR(27):CHAR(2):'P':SCRIPT:CHAR(13):
ECHO OFF
INPUT STAT:
ECHO ON
RETURN
END
|
Posted By: homerlh
Date Posted: March 22 2013 at 11:09am
|
Thanks for the code sample. But it is essentially the same as my code which does let me know when the PDF is there, but breaks the subsequent EMAIL.OUTLOOK call.
|
Posted By: Shrek59
Date Posted: March 23 2013 at 2:58pm
Hi Larry,
Maybe there is a timing issue here. Your program is searching to see if an item exists but subsequent processing fails ... perhaps the item isn't actually complete when that processing takes place.
I would try moving the SLEEP 1 to be before your test for the item's existence. That may be sufficient to get things working properly - until such time as the system is under a big load and it takes longer than that to generate the PDF.
The other thing to try is to get your PDF generation routine to write a "completion item" (e.g. ID.ITEM:'.txt') to the folder, and search for this item rather than the PDF. Once again, timing is important as you need to be sure that the completion item is created AFTER the PDF has finished being generated.
HTH,
Brian
|
Posted By: homerlh
Date Posted: March 24 2013 at 5:15am
Hi Brian,
Thanks for the suggestion. This code works fine to determine if the file exists, but it screws up the call to OUTLOOK.EMAIL later in the program. If this script is commented out, the OUTLOOK.MAIL works. I just added a sleep 2 to my program to give PDF_Creator time to do its work.
I have a big problem with my laptop. I had just typed this entire message - even longer when my hand scraped across the touch pad. Somehow it erased everything. It always happens when I forget to turn off the touchpad. I had totally disabled the touchpad by removing the drivers, but the PC got an update and now I cannot remove the drivers any more.
Oh well, thanks again for the suggestion.
Larry Hazel
|
Posted By: Tim Bristow
Date Posted: June 10 2013 at 2:03am
Hi Larry,
The routine below works for me when checking if a file exists. It uses the native Windows command line for checking.
SUBROUTINE LOCAL.FILE.EXISTS(FILE.NAME,EXISTS.FLG)
*
EXPORT.COPY.CMD = 'IF EXIST "':FILE.NAME:'" (ECHO 1) ELSE (ECHO 0)'
SEND.PATH = ""
SEND.FILE = ""
SEND.DATA = ""
GET.PATH = ""
GET.FILE = ""
GET.DATA = ""
EXISTS.FLG = ""
CALL DOSSVC(EXPORT.COPY.CMD,SEND.PATH,SEND.FILE,SEND.DATA,GET.PATH,GET.FILE,GET.DATA)
EXISTS.FLG = GET.DATA
RETURN
END
Hope this helps. Not sure if it will interfere with your outlook script.
Tim
|
Posted By: PSchellenbach
Date Posted: November 30 2018 at 9:32am
There is a subroutine in the SAMPLES file in the ACCUTERM account to test if a file exists. ATTESTFILE uses a script similar to the one posted here by palinder to check if a file exists. There is a companion subroutine, ATTESTDIR, to test if a directory exists. These have been included with AccuTerm for a long time (at least since 2000). Old versions of AccuTerm used different names (TEST.FILE and TEST.DIR) than the current version.
Thanks, Pete
|
|