How to resolve the algorithm Walk a directory/Recursively step by step in the ALGOL 68 programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Walk a directory/Recursively step by step in the ALGOL 68 programming language
Table of Contents
Problem Statement
Walk a given directory tree and print files matching a given pattern.
Note: This task is for recursive methods. These tasks should read an entire directory tree, not a single directory.
Note: Please be careful when running any code examples found here.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Walk a directory/Recursively step by step in the ALGOL 68 programming language
Source code in the algol programming language
INT match=0, no match=1, out of memory error=2, other error=3;
STRING slash = "/", pwd=".", parent="..";
PROC walk tree = (STRING path, PROC (STRING)VOID call back)VOID: (
[]STRING files = get directory(path);
FOR file index TO UPB files DO
STRING file = files[file index];
STRING path file = path+slash+file;
IF file is directory(path file) THEN
IF file NE pwd AND file NE parent THEN
walk tree(path file, call back)
FI
ELSE
call back(path file)
FI
OD
);
STRING re sort a68 = "[Ss]ort[^/]*[.]a68$";
PROC match sort a68 and print = (STRING path file)VOID:
IF grep in string(re sort a68, path file, NIL, NIL) = match THEN
print((path file, new line))
FI;
walk tree(".", match sort a68 and print)
You may also check:How to resolve the algorithm Last Friday of each month step by step in the Oforth programming language
You may also check:How to resolve the algorithm String matching step by step in the Python programming language
You may also check:How to resolve the algorithm Permutations by swapping step by step in the Java programming language
You may also check:How to resolve the algorithm Hello world/Standard error step by step in the Sidef programming language
You may also check:How to resolve the algorithm Terminal control/Ringing the terminal bell step by step in the R programming language