Logo

Programming-Idioms

  • PHP
  • Python
  • Scheme
  • Pascal
  • JS
  • C#
  • Lisp

Idiom #273 Check if folder is empty

Set the boolean b to true if the directory at filepath p is empty (i.e. doesn't contain any other files and directories)

(let ((b (directory p)))
  (if (null b) t nil))
$iterator = new FilesystemIterator($p, FilesystemIterator::SKIP_DOTS);
$b = (iterator_count($iterator) === 0);
import os
b = os.listdir(p) == []
uses FileUtil;
with FindAllFiles(p, AllFilesMask, False) do
try
  b := DirectoryExists(p) and (Count = 0);
finally
  Free;
end;
import 'dart:io';
var b = await Directory(p).list().isEmpty;

New implementation...
< >
programming-idioms.org