ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Checking if a directory exist in IFS

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Checking if a directory exist in IFS

    I am working on a CL that is supposed to copy a file from QTEMP to the IFS then zip the file and send it by email.
    how do I check if the directory exist in IFS and create the directory if it does not exist? The existing program I inherited used CPYTOPCD to copy the file to QDLS then email the report using SNDDST but the size of the attachment is too big so I am planning to zip the report before sending it by email.

  • #2
    What about running CRTDIR and monitoring for CPFA0A0?

    Comment


    • #3
      The system API to check if an IFS object (directory, file, etc) exists is the access() function. It can be used from ILE CL (though, it's a bit of a PITA... CL is a terrible language for IFS related stuff). You might consider using a shell script, RPG program, etc. to make this easier. Or, if it really must be done in CL, I'd create a little CHKDIR command to hide the complexity of calling the API, that way you can just call the CHKDIR command from CL, etc.

      Comment


      • #4
        You could consider using the CHKIFSOBJ utility from EASY400

        You find it here


        But I find Teds solution using CRTDIR and a MONMSG for the simplest way to do it.
        Last edited by Peder Udesen; February 3, 2022, 01:43 AM.

        Comment


        • #5
          What is the syntax for copying an object from a folder in QDLS to an IFS folder?

          Comment


          • #6
            What is the syntax for copying an object from a folder in QDLS to an IFS folder? How do I use CPYTOSTMF to copy from QTEMP to IFS?
            Last edited by JustinWithoutAnE; February 9, 2022, 07:51 AM.

            Comment


            • #7
              Code:
              CPY OBJ('/qdls/myflr/myfile.csv') TODIR('/home/somedir')
              
              CPYTOSTMF FROMMBR('/qsys.lib/qtemp.lib/xyz.file/xyz.mbr') TOSTMF('/home/mydir/xyz.text')

              Comment


              • #8
                I'm having trouble sending a zipped file by email. When I receive the zip file and try to open it it shows garbage and Notepad says the file is Macintosh(CR) but when I download the same file directly from the IFS it shows ups correctly and notepad says the file is WIndows(CRLF).

                Here's the code I am using. The report itself is generated in QTEMP with the file name in &NOMWRK.
                Code:
                CHGVAR VAR(&NOMDOC) VALUE(&NOMWRK *TCAT '.TXT')
                CPYTOPCD FROMFILE(QTEMP/&NOMWRK) TOFLR(RPT_MAIL) TODOC(&NOMDOC) REPLACE(*YES)
                
                CHGVAR VAR(&NOMTMP) VALUE('/QSYS.LIB/QTEMP.LIB/' *TCAT &NOMWRK *TCAT '.FILE/' *TCAT 'WEF30E0.MBR')
                CHGVAR VAR(&NOMZIP) VALUE(&NOMWRK *TCAT '.ZIP')
                CHGVAR VAR(&NOMIFS) VALUE('/REPORT_MAIL/' *TCAT &NOMDOC)
                CHGVAR VAR(&NOMARC) VALUE('/REPORT_MAIL/' *TCAT &NOMZIP)
                
                CRTDIR DIR(ESO_REPORT_MAIL)
                MONMSG MSGID(CPFA0A0)
                CPYTOSTMF FROMMBR(&NOMTMP) TOSTMF(&NOMIFS) STMFOPT(*REPLACE)
                
                CPYTOARCF FROMFILE(&NOMIFS) TOARCF(&NOMARC)
                I send the file using this command.
                Code:
                SNDSMTPEMM RCP((&EMAIL)) SUBJECT(&NOMMSG) ATTACH((&NOMARC *ZIP *BIN)) CHARSET(*UTF8)

                Comment


                • #9
                  In the CPYTOSTMF I think there is missing a specification of what characterset should be used for the streamfile.
                  Try STMFCCSID(*PCASCII) or STMFCCSID(1208) for UTF-8

                  Default for this parameter is *STMF and according to the help text it means:
                  If the stream file does not exist, the source database file
                  CCSID is used and associated with the stream file.


                  The source database file is normally in some of EBCDIC character sets.
                  Thus your ifs files CCSID is in EBCDIC not windows or UTF-8.

                  Comment

                  Working...
                  X