Empty directory: Difference between revisions

→‎{{header|Ruby}}: Replaced both existing examples by a simpler snippet,
(→‎{{header|Ruby}}: Replaced both existing examples by a simpler snippet,)
Line 524:
 
=={{header|Ruby}}==
Raises a SystemCallError if the named directory doesn’t exist.
{{works with|Ruby|1.8.7}}
<lang ruby># Checks if a directory is Dir.entries("testdir").empty, but raises? SystemCallError</lang>
# if _path_ is not a directory.
def empty_dir?(path)
Dir.foreach(path).none? {|f| f != '.' and f != '..'}
end</lang>
 
If Ruby is older than 1.8.7, then Dir.foreach must take a block.
 
<lang ruby># Checks if a directory is empty, but raises SystemCallError
# if _path_ is not a directory.
def empty_dir?(path)
Dir.foreach(path) {|f|
return false if f != '.' and f != '..'
}
return true
end</lang>
 
=={{header|Run BASIC}}==
1,149

edits