Empty directory: Difference between revisions

Rename Perl 6 -> Raku, alphabetize, minor clean-up
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 96:
{{out}}
<pre>false</pre>
 
=={{header|AWK}}==
<lang AWK>
Line 301 ⟶ 302:
/etc/passwd: Not a directory
</pre>
 
=={{header|C++}}==
{{libheader|Boost}}
<lang cpp>
#include <iostream>
#include <boost/filesystem.hpp>
 
using namespace boost::filesystem;
 
int main(int argc, char *argv[])
for (int i = 1; i < argc; ++i) {
path p(argv[i]);
 
if (exists(p) && is_directory(p))
std::cout << "'" << argv[i] << "' is" << (!is_empty(p) ? " not" : "") << " empty\n";
else
std::cout << "dir '" << argv[i] << "' could not be found\n";
}
</lang>
 
=={{header|C sharp}}==
Line 351 ⟶ 331:
'c:\temp\empty' is empty
</pre>
 
=={{header|C++}}==
{{libheader|Boost}}
<lang cpp>
#include <iostream>
#include <boost/filesystem.hpp>
 
using namespace boost::filesystem;
 
int main(int argc, char *argv[])
for (int i = 1; i < argc; ++i) {
path p(argv[i]);
 
if (exists(p) && is_directory(p))
std::cout << "'" << argv[i] << "' is" << (!is_empty(p) ? " not" : "") << " empty\n";
else
std::cout << "dir '" << argv[i] << "' could not be found\n";
}
</lang>
 
=={{header|Clojure}}==
Line 359 ⟶ 360:
(assert (.isDirectory file))
(-> file .list empty?))) ; .list ignores "." and ".."</lang>
 
 
=={{header|CoffeeScript}}==
Line 413:
{ok,[]}
</pre>
 
=={{header|F_Sharp|F#}}==
<lang fsharp>open System.IO
let isEmptyDirectory x = (Directory.GetFiles x).Length = 0 && (Directory.GetDirectories x).Length = 0</lang>
 
=={{header|Factor}}==
Line 467 ⟶ 471:
'c:\freebasic\docs' is empty
</pre>
 
=={{header|F_Sharp|F#}}==
<lang fsharp>open System.IO
let isEmptyDirectory x = (Directory.GetFiles x).Length = 0 && (Directory.GetDirectories x).Length = 0</lang>
 
=={{header|Gambas}}==
Line 519:
}
</lang>
 
=={{header|Groovy}}==
Solution:
Line 709 ⟶ 710:
end proc;
</lang>
 
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
Line 759:
}
}</lang>
 
 
=={{header|NewLISP}}==
Line 847 ⟶ 846:
<lang perl>use IO::Dir;
sub dir_is_empty { !grep !/^\.{1,2}\z/, IO::Dir->new(@_)->read }</lang>
 
=={{header|Perl 6}}==
<lang perl6>sub dir-is-empty ($d) { not dir $d }</lang>
The <tt>dir</tt> function returns a lazy list of filenames, excluding "<tt>.</tt>" and "<tt>..</tt>" automatically. Any boolean context (in this case the <tt>not</tt> function) will do just enough work on the lazy list to determine whether there are any elements, so we don't have to count the directory entries, or even read them all into memory, if there are more than one buffer's worth.
 
=={{header|Phix}}==
Line 915 ⟶ 910:
{{out}}
<pre>myDir is not empty</pre>
 
 
=={{header|PowerShell}}==
Line 992 ⟶ 986:
(empty? (directory-list "some-directory"))
</lang>
 
=={{header|Perl 6Raku}}==
(formerly Perl 6)
<lang perl6>sub dir-is-empty ($d) { not dir $d }</lang>
The <tt>dir</tt> function returns a lazy list of filenames, excluding "<tt>.</tt>" and "<tt>..</tt>" automatically. Any boolean context (in this case the <tt>not</tt> function) will do just enough work on the lazy list to determine whether there are any elements, so we don't have to count the directory entries, or even read them all into memory, if there are more than one buffer's worth.
 
=={{header|REXX}}==
Line 1,103 ⟶ 1,102:
)
end;</lang>
 
 
=={{header|Tcl}}==
10,333

edits