Deletes any empty directories under the given directory.
The startDirIsJavaObject is private to this implementation's
recursion needs.
977437
function (startDir, startDirIsObject) {
            var topDir = startDir,
                dirFileArray, fileObj;

            if (!startDirIsObject) {
                topDir = xpfile(startDir);
            }

            if (topDir.exists()) {
                dirFileArray = topDir.directoryEntries;
                while (dirFileArray.hasMoreElements()) {
                    fileObj = dirFileArray.getNext().QueryInterface(Ci.nsILocalFile);

                    if (fileObj.isDirectory()) {
                        file.deleteEmptyDirs(fileObj, true);
                    }
                }

                //If the directory is empty now, delete it.
                dirFileArray = topDir.directoryEntries;
                if (!dirFileArray.hasMoreElements()) {
                    file.deleteFile(topDir.path);
                }
            }
        }
415573
public static void deleteRecursive(@Nonnull File dir) throws IOException {
        deleteRecursive(fileToPath(dir), PathRemover.PathChecker.ALLOW_ALL);
    }
1087594
def delete_directories(paths):
    
    for path in paths:
        if os.path.exists(path):
            shutil.rmtree(path)
876140
public static void mkdirs(File directory) throws CreateDirectoryException {
    if (directory.exists()) {
      // file exists and *is* a directory
      if (directory.isDirectory()) {
        return;
      }

      // file exists, but is not a directory - delete it
      if (!directory.delete()) {
        throw new CreateDirectoryException(
            directory.getAbsolutePath(),
            new FileDeleteException(directory.getAbsolutePath()));
      }
    }

    // doesn't exist. Create one
    if (!directory.mkdirs() && !directory.isDirectory()) {
      throw new CreateDirectoryException(directory.getAbsolutePath());
    }
  }
1178418
function cleanDistDir(dir) {
  /* istanbul ignore else */
  if (dir !== process.cwd()) {
    fs.stat(dir, (err) => {
      if (!err) {
        del.sync([dir]);
      }

      fs.mkdirSync(dir);
    });
  }
}
1108141
protected function emptyDirectory($directory, $deleteDirectory = false)
	{
		if (!is_dir($directory) || !($directoryHandle = opendir($directory))) {
			return;
		}
		
		while (false !== ($object = readdir($directoryHandle))) 
		{
			if ($object == '.' || $object == '..') {
				continue;
			}

			if (!is_dir($directory.'/'.$object)) {
				unlink($directory.'/'.$object);
			}
			else {
				$this->emptyDirectory($directory.'/'.$object, true);	// The object is a folder, recurse through it.
			}
		}
		
		if ($deleteDirectory)
		{
			closedir($directoryHandle);
			rmdir($directory);
		}
	}
1080941
private static synchronized int deleteRecursively(File directory) {
		int deleted = 0;
		if(directory.isDirectory()) {
			File[] contents = directory.listFiles();
			for(File file : contents) {
				deleted += deleteRecursively(file);
			}
		} else {
			deleted++;
		}
		directory.delete();
		return deleted;
	}
464933
function (startDir) {
            var dirFileArray, i, fileName, filePath, stat;

            if (file.exists(startDir)) {
                dirFileArray = fs.readdirSync(startDir);
                for (i = 0; i < dirFileArray.length; i++) {
                    fileName = dirFileArray[i];
                    filePath = path.join(startDir, fileName);
                    stat = fs.statSync(filePath);
                    if (stat.isDirectory()) {
                        file.deleteEmptyDirs(filePath);
                    }
                }

                //If directory is now empty, remove it.
                if (fs.readdirSync(startDir).length ===  0) {
                    file.deleteFile(startDir);
                }
            }
        }
1301146
protected static void deleteDir(File dir) {

        String files[] = dir.list();
        if (files == null) {
            files = new String[0];
        }
        for (int i = 0; i < files.length; i++) {
            File file = new File(dir, files[i]);
            if (file.isDirectory()) {
                deleteDir(file);
            } else {
            	try {
            		file.delete();
            	} catch (SecurityException se) {
            		log.error("The file " + file.getAbsolutePath() + " couldn't be deleted");
            	}
            }
        }
        try {
        	dir.delete();
        } catch (SecurityException se) {
    		log.error("The directory " + dir.getAbsolutePath() + " couldn't be deleted");
    	}
    }
748844
protected void deleteDirectory(File directoryName){
		if (debugLogger.isLoggable(Level.FINE) && isDebugEnabled()) {
			debugLogger.logp(Level.FINE, thisClass, "deleteDirectory", "empty directory "+((directoryName == null) ? "None":
				directoryName.getPath()));
		}		
		if (AccessHelper.deleteFile(directoryName)) {  // If directory is empty, delete
			if (debugLogger.isLoggable(Level.FINE) && isDebugEnabled()) {
				debugLogger.logp(Level.FINE, thisClass, "deleteDirectory", "delete "+directoryName.getName());
			}					
		} else {
			// Else the directory is not empty, and deletion fails
			if (isDebugEnabled()) {
				debugLogger.logp(Level.WARNING, thisClass, "deleteDirectory", "Failed to delete directory "+directoryName.getPath());
			}
		}
	}
1033312
@CliObjectOption(description = "If deleting files on target, also delete newly empty parent directories.")
  public EmbeddedGobblinDistcp deleteEmptyParentDirectories() {
    this.setConfiguration(RecursiveCopyableDataset.DELETE_EMPTY_DIRECTORIES_KEY, Boolean.toString(true));
    return this;
  }
138119
public static void cleanDirectory(File directory) throws IOException {
    requireNonNull(directory, DIRECTORY_CAN_NOT_BE_NULL);
    if (!directory.exists()) {
      return;
    }

    cleanDirectoryImpl(directory.toPath());
  }
3766
public static void deleteDirOnExit(final File dir) {
        if (dir.isDirectory()) {
            final String[] children = dir.list();
            for (int i = 0; i < children.length; i++) {
                deleteDirOnExit(new File(dir, children[i]));
            }
        }

        // The directory is now empty so delete it
        dir.deleteOnExit();
    }
1264625
public static void deleteDirectory(Path dir) throws IOException {
		if(dir == null || !Files.exists(dir))
			return;
		Files.walkFileTree(dir, new SimpleFileVisitor<Path>() {
	        @Override
	        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
	            Files.delete(file);
	            return FileVisitResult.CONTINUE;
	        }

	        @Override
	        public FileVisitResult postVisitDirectory(Path dir, IOException e) throws IOException {
	            if (e != null) {
	                throw e;
	            }
	            Files.delete(dir);
	            return FileVisitResult.CONTINUE;
	        }
	    });
	}
329895
public static function emptyDirectory(string $directory): void
    {
        if (is_dir($directory)) {
            foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($directory, \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST) as $path) {
                if ($path->isFile()) {
                    if (!unlink($path->getPathname())) {
                        throw new FilesystemException("Unable to empty directory while emptying directory on path={$path->getPathname()}");
                    }
                } else {
                    if (!rmdir($path->getPathname())) {
                        throw new FilesystemException("Unable to empty directory while emptying directory on path={$path->getPathname()}");
                    }
                }
            }
        }
    }
1048298
public static boolean clearDirectory(File directory) {
		Assert.isTrue(directory.isDirectory(), "Parameter ist kein Verzeichnis");
		File[] files = directory.listFiles();
		boolean allDeleted = true;
		for (File file : files) {
			if (file.isDirectory()) {
				clearDirectory(file);
			}
			allDeleted &= file.delete();
		}

		return allDeleted;
	}
844437
public static void cleanDirectory(File directory) throws IOException {
    requireNonNull(directory, DIRECTORY_CAN_NOT_BE_NULL);

    Path path = directory.toPath();
    if (!path.toFile().exists()) {
      return;
    }

    cleanDirectoryImpl(path);
  }