Deletes given directory (and does not reason about symlinks). If the
given directory does not exist, this method does nothing.

@param dir
Directory to delete
163884
public static void deleteDirectory(File dir) {
        if (!dir.exists()) {
            return;
        }

        if (dir.isDirectory()) {
            for (File child : dir.listFiles()) {
                deleteDirectory(child);
            }
            dir.delete();
        } else {
            dir.delete();
        }
    }
1107891
public static void deleteDirContents(File dir) {
        if (!dir.isDirectory() || !dir.exists()) {
            throw new IllegalArgumentException(dir.getAbsolutePath()
                    + " is not a directory or does not exist.");
        }
        String[] children = dir.list();
        for (int i = 0; i < children.length; i++) {
            File f = new File(dir, children[i]);
            if (f.isDirectory()) {
                deleteDirContents(f);
            }
            f.delete();
        }
    }
777903
private static void rmDir(File dir) {
        for (File file: dir.listFiles()) {
            if (file.isDirectory()) {
                rmDir(file);
            } else {
                if (!file.delete()) {
                    logger.warn("Can't delete file " + file);
                }
            }
        }
        if (!dir.delete()) {
            logger.warn("Can't delete dir " + dir);
        }
    }
531339
public static boolean deleteDir(File dir) {
        if (dir.isDirectory()) {
            File[] children = dir.listFiles();
            for (File child : children) {
                boolean success = deleteDir(child);
                if (!success) {
                    return false;
                }
            }
        }
        return dir.delete();
    }
1156861
public static void createDirectory(final String directory) {
        if (directory == null) return;
        final File f = new File(directory);
        if (!f.isDirectory()) {
            if (!f.mkdir()) throw new RuntimeException("couldn't create "
                    + directory);
        }
    }
518027
public static void deleteDirRecursive(File dir) throws IOException {
        File failed = deleteDirRecursiveInternal(dir, true);
        if (failed != null) {
            throw new IOException("Could not delete file: " + failed.getPath());
        }
    }
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;
	}
296806
protected function deleteDirectory($dir)
    {
        $files = new RecursiveIteratorIterator(
            new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS),
            RecursiveIteratorIterator::CHILD_FIRST
        );

        foreach ($files as $fileInfo) {
            $todo = ($fileInfo->isDir() ? 'rmdir' : 'unlink');

            $todo($fileInfo->getRealPath());
        }

        rmdir($dir);
    }
229254
public static boolean deleteDirectory(File dir)
    {

        if (dir.canWrite()) {
            File [] subFiles = dir.listFiles();

            for(int i=0; i<subFiles.length; i++) {
                if (subFiles[i].isDirectory())
                    deleteDirectory(subFiles[i]);
                else
                    subFiles[i].delete();
            }

        }

        return dir.delete();

    }
334244
public static function delete_dir($dir)
    {
        // This code can be executed from command line, make sure
        // we have permissions to delete keys directory
        if (!is_writable($dir)) {
            rcube::raise_error("Unable to delete $dir", false, true);
            return false;
        }

        if ($content = scandir($dir)) {
            foreach ($content as $filename) {
                if ($filename != '.' && $filename != '..') {
                    $filename = $dir . DIRECTORY_SEPARATOR . $filename;

                    if (is_dir($filename)) {
                        self::delete_dir($filename);
                    }
                    else {
                        unlink($filename);
                    }
                }
            }

            rmdir($dir);
        }

        return true;
    }
30363
public void cleanDirectory( final File directory )
        throws IOException
    {
        if ( !directory.exists() )
        {
            final String message = directory + " does not exist";
            throw new IllegalArgumentException( message );
        }

        if ( !directory.isDirectory() )
        {
            final String message = directory + " is not a directory";
            throw new IllegalArgumentException( message );
        }

        Delete deleteTask = new Delete();
        deleteTask.setProject(getProject());
		deleteTask.setDir(directory);
		deleteTask.execute();
		
		if(!directory.exists()){
			directory.mkdirs();
		}
    }
1032
public static function deleteAllFilesInDirectory ($dir) {
        $dirIterator = new \RecursiveDirectoryIterator($dir, \FilesystemIterator::SKIP_DOTS);
        foreach (new \RecursiveIteratorIterator($dirIterator, \RecursiveIteratorIterator::CHILD_FIRST) as $file) {
            $file->isDir() ? rmdir($file) : unlink($file);
        }
    }
1272641
private void deleteContents(File dir) {
        if (dir != null && dir.exists()) {
            for (File f : dir.listFiles()) {
                if (f.isDirectory()) {
                    deleteContents(f);
                }
                if (!options.isUnidentifiedArtifactPermitted(f.getAbsolutePath())) {
                    Log.debug("Removing "+f.getAbsolutePath());
                    f.delete();
                }
            }
        }
    }
1161963
public static void checkValidDir(final File dir) {
        checkNotNull("dir", dir);
        if (!dir.exists()) {
            throw new IllegalArgumentException("The directory '" + dir + "' does not exist!");
        }
        if (!dir.isDirectory()) {
            throw new IllegalArgumentException("The name '" + dir + "' is not a directory!");
        }
    }
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);
  }
145839
public static void recursivelyDeleteDirectory(File directory) throws IOException {
    if (!directory.exists()) {
      return;
    }
    checkArgument(directory.isDirectory(), "Cannot recursively delete a non-directory");
    walkFileTree(directory.toPath(), new DeletionFileVisitor());
  }
1356380
private static void deleteContents(File dir) {
        if (dir != null && dir.exists()) {
            for (File f : dir.listFiles()) {
                if (f.isDirectory()) {
                    deleteContents(f);
                }
                f.delete();
            }
        }
    }