Empty directory: Difference between revisions

m (→‎{{header|Java}}: I added this from my phone and somehow it autocorrected the method name...)
Line 49:
/etc/passwd: Not a directory
</pre>
 
==Icon and {{header|Unicon}}==
This example uses Unicon extensions. The 'empty' sub-directory was manually setup for this test.
<lang Icon>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</lang>
 
Output:<pre>. is not empty
./empty is empty</pre>
 
=={{header|Java}}==
Anonymous user