ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

check the existence of the stream file in IFS

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

  • check the existence of the stream file in IFS

    Hi All,

    How could I check the existence of the stream file in IFS?
    Suppose I have a stream file /TEST/print.xml then how can I know that this particular stream file is exist inside an Directory.
    Is there any API to find out the same.

    Thanks in advance.

    Regards
    Skma

  • #2
    Re: check the existence of the stream file in IFS

    try this out for size

    Code:
    Daccess           PR            10I 0 extproc('access')                
    Dpathptr1                         *   value                            
    Dmode1                          10I 0 value                            
     *                                                                     
     * IFS API Constants                                                   
     *                                                                     
    DF_OK             S             10I 0 inz(0)                           
     *                                                                     
     * Some working environment for us                                     
     *                                                                     
    DFile_exists      S             10I 0                                  
    Dpathptr          S               *                                    
    Dpathname         S             30                                     
    DExists           C                   'File Exists'                    
    DNotExists        C                   'File does not exist'            
     *                                                                     
     * Main{}                                                              
     *                                                                     
    C     *entry        plist                                              
    C                   parm                    filename         30        
     * Set a character pointer to the file name string                     
    C                   eval      pathname = %trim(filename)               
    C                   eval      pathptr = %addr(pathname)                
     * Call the IFS API                                                    
    C                   eval      File_Exists = access(pathptr:F_OK)       
     * Did we find it?                                                     
    C     File_exists   ifeq      0                                        
    C     Exists        dsply                                              
    C                   else                                               
    C     NotExists     dsply                                              
    C                   endif                                              
     * Thats all folks                                                     
    C                   move      *on           *inlr
    All my answers were extracted from the "Big Dummy's Guide to the As400"
    and I take no responsibility for any of them.

    www.code400.com

    Comment


    • #3
      Re: check the existence of the stream file in IFS

      Hello,

      or use CLP (just an example, do changes by your own)

      PHP Code:
                   PGM        PARM(&NAME)
                   
                   
      DCL        VAR(&OBJ1TYPE(*CHARLEN(18) +
                                
      VALUE('/HOME/whateverxxx/')
                   
      DCL        VAR(&OBJ2TYPE(*CHARLEN(30)
                   
                   
      CHGVAR     VAR(&OBJ2VALUE(&OBJ1 *CAT &NAME)
       
                   
      CHKOUT     OBJ(&OBJ2)
                   
      MONMSG     MSGID(CPFA0A9EXEC(DO)
                   
      SNDPGMMSG  MSG(&OBJ2 *CAT ' not found')
                   
      /* DO HERE SOME CODE IF NOT FOUND */
                   
      GOTO       CMDLBL(LOOP)
                   
      ENDDO
                   SNDPGMMSG  MSG
      (&OBJ2 *CAT ' found')
                   
      /* DO HERE SOME CODE IF FOUND */
           
      LOOP:   CHKIN      OBJ(&OBJ2)
                   
      MONMSG     MSGID(CPFA0A9)
                   
                   
      ENDPGM 
      kuempi

      Comment


      • #4
        Re: check the existence of the stream file in IFS

        Originally posted by jamief View Post
        try this out for size

        Code:
        [B]Daccess           PR            10I 0 extproc('access')  [/B]              
        Dpathptr1                         *   value                            
        Dmode1                          10I 0 value                            
         *                                                                     
         * IFS API Constants                                                   
         *                                                                     
        DF_OK             S             10I 0 inz(0)                           
         *                                                                     
         * Some working environment for us                                     
         *                                                                     
        DFile_exists      S             10I 0                                  
        Dpathptr          S               *                                    
        Dpathname         S             30                                     
        DExists           C                   'File Exists'                    
        DNotExists        C                   'File does not exist'            
         *                                                                     
         * Main{}                                                              
         *                                                                     
        C     *entry        plist                                              
        C                   parm                    filename         30        
         * Set a character pointer to the file name string                     
        C                   eval      pathname = %trim(filename)               
        C                   eval      pathptr = %addr(pathname)                
         * Call the IFS API                                                    
        C                   eval      File_Exists = access(pathptr:F_OK)       
         * Did we find it?                                                     
        C     File_exists   ifeq      0                                        
        C     Exists        dsply                                              
        C                   else                                               
        C     NotExists     dsply                                              
        C                   endif                                              
         * Thats all folks                                                     
        C                   move      *on           *inlr
        Where Do I find ExtProc('access'). Will I have to write the procedure?

        Comment


        • #5
          Re: check the existence of the stream file in IFS

          Originally posted by rashmimalpani View Post
          Where Do I find ExtProc('access'). Will I have to write the procedure?
          You don't need to just ensure your header spec contains BNDDIR('QC2LE')
          Bill
          "A good friend will bail you out of jail,
          A true friend would be sitting beside you saying,
          'Wow, that was fun.'"

          Comment


          • #6
            Re: check the existence of the stream file in IFS

            Originally posted by Billw View Post
            You don't need to just ensure your header spec contains BNDDIR('QC2LE')
            Hey thanks for the reply...It worked...The problem was i had given ExtProc('Access') instead of ExtProc('access')
            Last edited by rashmimalpani; January 18, 2010, 09:56 PM.

            Comment


            • #7
              Re: check the existence of the stream file in IFS

              Hi,

              I tried using this process, but always I am getting the message "File does not exist". I gave the full path of file in IFS as the parameter... and also tried with just giving the file name only. In both cases, I got the same return value. I am not sure what am I doing wrong. Will it look at QDLS only or anything under root ? ('/') ? If I have subfolders where I need to check the existence of the file, can I give the entire path?
              Please let me know your suggestions..

              Thanks
              PR.

              Comment

              Working...
              X