cleanEmpty method

Future<void> cleanEmpty()

Delete empty directories and files. An empty file is a file that has a length of 0 bytes. An empty directory is a directory that contains no files or directories

Implementation

Future<void> cleanEmpty() async {
  if (await exists()) {
    if (this is File) {
      if (isEmpty) {
        consoleLog("Deleting empty directory: $this");
        await delete();
      }
      await parent.cleanEmpty();
    } else if (this is Directory) {
      for (var e in (this as Directory).listSync()) {
        await e.cleanEmpty();
      }
      if (isEmpty) {
        consoleLog("Deleting empty directory: $this");
        await delete();
      }
    }
  }
}