How to resolve the algorithm Empty directory step by step in the Icon and Unicon programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Empty directory step by step in the Icon and Unicon programming language
Table of Contents
Problem Statement
Starting with a path to some directory, determine whether the directory is empty. An empty directory contains no files nor subdirectories. With Unix or Windows systems, every directory contains an entry for “.” and almost every directory contains “..” (except for a root directory); an empty directory contains no other entries.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Empty directory step by step in the Icon and Unicon programming language
Source code in the icon programming language
procedure main()
every dir := "." | "./empty" do
write(dir, if isdirempty(dir) then " is empty" else " is not empty")
end
procedure isdirempty(s) #: succeeds if directory s is empty (and a directory)
local d,f
if ( stat(s).mode ? ="d" ) & ( d := open(s) ) then {
while f := read(d) do
if f == ("."|"..") then next else fail
close(d)
return s
}
else stop(s," is not a directory or will not open")
end
You may also check:How to resolve the algorithm Dice game probabilities step by step in the JavaScript programming language
You may also check:How to resolve the algorithm String concatenation step by step in the K programming language
You may also check:How to resolve the algorithm CSV to HTML translation step by step in the Applesoft BASIC programming language
You may also check:How to resolve the algorithm Abundant, deficient and perfect number classifications step by step in the Clojure programming language
You may also check:How to resolve the algorithm Binary search step by step in the AArch64 Assembly programming language