Task

Walk a given directory and print the names of files matching a given pattern.

(How is "pattern" defined? substring match? DOS pattern? BASH pattern? ZSH pattern? Perl regular expression?)


Note: This task is for non-recursive methods.   These tasks should read a single directory, not an entire directory tree.

Note: Please be careful when running any code presented here.



Related task

   Walk Directory Tree   (read entire directory tree). 


CHARACTER dirtxt='dir.txt', filename*80
 
SYSTEM(DIR='*.*', FIle=dirtxt) ! "file names", length, attrib, Created, LastWrite, LastAccess
OPEN(FIle=dirtxt, Format='"",', LENgth=files) ! parses column 1 ("file names")
 
DO nr = 1, files
  filename = dirtxt(nr,1) ! reads dirtxt row = nr, column = 1 to filename
  ! write file names with extensions "txt", or "hic", or "jpg" (case insensitive) using RegEx option =128:
  IF( INDEX(filename, "\.txt|\.hic|\.jpg", 128) ) WRITE() filename 
ENDDO