How to resolve the algorithm Walk a directory/Non-recursively step by step in the Action! programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Walk a directory/Non-recursively step by step in the Action! programming language

Table of Contents

Problem Statement

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.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Walk a directory/Non-recursively step by step in the Action! programming language

Source code in the action! programming language

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

  

You may also check:How to resolve the algorithm Count in octal step by step in the Befunge programming language
You may also check:How to resolve the algorithm System time step by step in the J programming language
You may also check:How to resolve the algorithm Random numbers step by step in the AWK programming language
You may also check:How to resolve the algorithm Idiomatically determine all the characters that can be used for symbols step by step in the J programming language
You may also check:How to resolve the algorithm Semordnilap step by step in the SuperCollider programming language