| 
    
Hello Jaime,
> Does anybody know how to check if a file, that we just know the first 5
> possitions and the extension exists in a folder of the IFS?
> Something like the access api, but with wild cards?
You can't use the access() API, but you can use the opendir(), readdir(),
closedir() APIs to read through the files in a directory and check to see
if one or more of them matches your pattern.
For example, the following program checks to to see if there's any files
in the /home/klemscot directory that start with the letter 'e' and end
with the letters '.txt'.  If at least one file is found, the "FOUND" field
is set *ON.
     H DFTACTGRP(*NO)
      *
      *  You can get the ifsio_h member from my IFS tutorial
      *  http://www.scottklement.com/rpg/ifs.html
      *
      /copy ifsio_h
     D msg             s             52A
     D dirHandle       s               *
     D name            s            640A   varying
     D found           s              1N   inz(*OFF)
     c                   eval      *inlr = *on
     c                   eval      dirHandle = opendir('/home/klemscot')
     c                   if        dirHandle = *NULL
     c                   eval      msg = 'opendir() failed.'
     c                   dsply                   msg
     c                   return
     c                   endif
     c                   eval      p_dirent = readdir(dirHandle)
     c                   dow       p_dirent <> *NULL
     c                   eval      name = %subst(d_name:1:d_namelen)
     c                   if         %len(name) > 5
     c                              and
     c                              %subst(name: 1: 1) = 'e'
     c                              and
     c                              %subst(name: %len(name)-3: 4) = '.txt'
     c                   eval       found = *ON
     c                   endif
     c                   eval      p_dirent = readdir(dirHandle)
     c                   enddo
     c                   callp     closedir(dirHandle)
     c                   return
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.