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). 


PROC GetFileName(CHAR ARRAY line,fname)
  BYTE i,len
 
  len=0
  i=3
  FOR i=3 TO 10
  DO
    IF line(i)=32 THEN EXIT FI
    len==+1
    fname(len)=line(i)
  OD
  len==+1
  fname(len)='.
  FOR i=11 TO 13
  DO
    IF line(i)=32 THEN EXIT FI
    len==+1
    fname(len)=line(i)
  OD
  fname(0)=len
RETURN
 
PROC Dir(CHAR ARRAY filter)
  CHAR ARRAY line(255),fname(255)
  BYTE dev=[1]
 
  PrintE(filter)
  Close(dev)
  Open(dev,filter,6)
  DO
    InputSD(dev,line)
    IF line(0)=0 OR line(0)>0 AND line(1)#32 THEN
      EXIT
    FI
    GetFileName(line,fname)
    Put(32) PrintE(fname)
  OD
  Close(dev)
  PutE()
RETURN
 
PROC Main()
  Dir("D:*.*")
  Dir("H1:X*.*")
  Dir("H1:?????.ACT")
  Dir("H1:??F*.*")
RETURN