How to resolve the algorithm Walk a directory/Non-recursively step by step in the Forth 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 Forth 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 Forth programming language
Source code in the forth programming language
defer ls-filter ( name len -- ? )
: ls-all 2drop true ;
: ls-visible drop c@ [char] . <> ;
: ls ( dir len -- )
open-dir throw ( dirid )
begin
dup pad 256 rot read-dir throw
while
pad over ls-filter if
cr pad swap type
else drop then
repeat
drop close-dir throw ;
\ only show C language source and header files (*.c *.h)
: c-file? ( str len -- ? )
dup 3 < if 2drop false exit then
+ 1- dup c@
dup [char] c <> swap [char] h <> and if drop false exit then
1- dup c@ [char] . <> if drop false exit then
drop true ;
' c-file? is ls-filter
s" ." ls
You may also check:How to resolve the algorithm Active Directory/Search for a user step by step in the PicoLisp programming language
You may also check:How to resolve the algorithm Factorial step by step in the Joy programming language
You may also check:How to resolve the algorithm XML/Input step by step in the Wren programming language
You may also check:How to resolve the algorithm Ulam spiral (for primes) step by step in the 11l programming language
You may also check:How to resolve the algorithm Rep-string step by step in the J programming language