Rocket Software Homepage
Forum Home Forum Home > AccuTerm Knowledge Base (read only) > GUI Development
  New Posts New Posts RSS Feed - See if file exists in Windows Folder
  FAQ FAQ  Forum Search   Register Register  Login Login

The AccuTerm forum has moved. Go to community.rocketsoftware.com to register for the new Rocket forum.

Forum LockedSee if file exists in Windows Folder

 Post Reply Post Reply
Author
Message
homerlh View Drop Down
Beta Tester
Beta Tester


Joined: November 11 2004
Location: United States
Status: Offline
Points: 288
Post Options Post Options   Thanks (0) Thanks(0)   Quote homerlh Quote  Post ReplyReply Direct Link To This Post Topic: See if file exists in Windows Folder
    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
Back to Top
palinder View Drop Down
Groupie
Groupie


Joined: June 08 2012
Location: United States
Status: Offline
Points: 51
Post Options Post Options   Thanks (0) Thanks(0)   Quote palinder Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
homerlh View Drop Down
Beta Tester
Beta Tester


Joined: November 11 2004
Location: United States
Status: Offline
Points: 288
Post Options Post Options   Thanks (0) Thanks(0)   Quote homerlh Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
Shrek59 View Drop Down
Senior Member
Senior Member


Joined: December 04 2006
Location: New Zealand
Status: Offline
Points: 208
Post Options Post Options   Thanks (0) Thanks(0)   Quote Shrek59 Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
homerlh View Drop Down
Beta Tester
Beta Tester


Joined: November 11 2004
Location: United States
Status: Offline
Points: 288
Post Options Post Options   Thanks (0) Thanks(0)   Quote homerlh Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
Tim Bristow View Drop Down
Newbie
Newbie


Joined: February 27 2012
Location: United Kingdom
Status: Offline
Points: 7
Post Options Post Options   Thanks (0) Thanks(0)   Quote Tim Bristow Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
PSchellenbach View Drop Down
Admin Group
Admin Group

Moderator

Joined: December 15 2003
Location: United States
Status: Offline
Points: 2150
Post Options Post Options   Thanks (0) Thanks(0)   Quote PSchellenbach Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.03
Copyright ©2001-2019 Web Wiz Ltd.