Delete a directory and all its contents.  If
we return false, the directory may be partially-deleted.
423164
public static boolean fullyDelete(File dir) throws IOException {
    boolean deleted = true;
    File contents[] = dir.listFiles();
    if (contents != null) {
      for (int i = 0; i < contents.length; i++) {
        if (contents[i].isFile()) {
          if (!contents[i].delete()) {
            deleted = false;
          }
        } else {
          //try deleting the directory
          // this might be a symlink
          boolean b = false;
          b = contents[i].delete();
          if (b){
            //this was indeed a symlink or an empty directory
            continue;
          }
          // if not an empty directory or symlink let
          // fullydelete handle it.
          if (!fullyDelete(contents[i])) {
            deleted = false;
          }
        }
      }
    }
    return dir.delete() && deleted;
  }
625326
public static boolean delete(File file) {
        boolean result = true;

        if (file == null) {
            return false;
        }
        if (file.exists()) {
            if (file.isDirectory()) {
                // 1. delete content of directory:
                File[] children = file.listFiles();
                for (File child : children) { //for each file:
                    result = result && delete(child);
                }//next file
            }
            result = result && file.delete();
        } //else: input directory does not exist or is not a directory
        return result;
    }
173970
public static boolean deleteDir(File dir) {
		if (dir != null && dir.isDirectory()) {
			String[] children = dir.list();
			for (int i = 0; i < children.length; i++) {
				if (!deleteDir(new File(dir, children[i])))
					return false;
			}
		}
		return dir.delete();
	}
92533
def try_remove(self):
        
        if self.islink():
            self.unlink()
        elif self.isfile():
            self.remove()
        elif self.isdir():
            self.empty_directory()
            if self.isdir():
                self.rmdir()
        else:
            return False
        return True
650044
public function deleteDirectories($directory)
    {
        $allDirectories = $this->directories($directory);

        if (! empty($allDirectories)) {
            foreach ($allDirectories as $directoryName) {
                $this->deleteDirectory($directoryName);
            }

            return true;
        }

        return false;
    }
755661
def _clear_dir(dirName):
    
    # If we got here, clear dir  
    for fname in os.listdir(dirName):
        try:
            os.remove( os.path.join(dirName, fname) )
        except Exception:
            pass
    try:
        os.rmdir(dirName)
    except Exception:
        pass
751497
private boolean delete(final File f) throws IOException {

		if (f.isDirectory()) {
			final File[] files = f.listFiles();
			if (files != null) {
				for (File file : files) {
					final boolean del = delete(file);
					if (!del) {
						return false;
					}
				}
			}
		} else {
			return f.delete();
		}

		// Now directory is empty
		return f.delete();
	}
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();
    }
1063054
def clear_dir(self):
        """"""
        self.stdout.write("Deleting contents of '{}'.".format(self.destination_path))

        for filename in os.listdir(self.destination_path):
            if os.path.isfile(filename) or os.path.islink(filename):
                os.remove(filename)
            elif os.path.isdir(filename):
                shutil.rmtree(filename)
264769
public static void purgeDirectory(File directory) {

        if (directory.canRead() && directory.isDirectory()) {
            File[] files = directory.listFiles();
            for (int i = 0; i < files.length; i++) {
                File f = files[i];
                if (f.isDirectory()) {
                    purgeDirectory(f);
                }
                if (f.canWrite()) {
                    f.delete();
                }
            }
            directory.delete();
        }
    }
248698
public static function deleteDirectoryContents($directory, $DELETE_DIRECTORY = false)
    {
        $files = array_diff(scandir($directory), ['.', '..']);
        foreach ($files as $file) {
            $path = Util::get_path([$directory, $file]);
            (
                is_dir($path)
                ? self::delete_directory_contents($path, true)
                : unlink($path)
            );
        }

        return $DELETE_DIRECTORY ? rmdir($directory) : true;
    }
302378
def remove_directory(self, directory_name, *args, **kwargs):
		
		previous_path = self.session_path()
		try:
			self.session_path(directory_name)
			os.rmdir(self.full_path())
		finally:
			self.session_path(previous_path)
902518
public static void deleteDirectory(File directory) throws IOException {
    requireNonNull(directory, DIRECTORY_CAN_NOT_BE_NULL);

    if (!directory.exists()) {
      return;
    }

    Path path = directory.toPath();
    if (Files.isSymbolicLink(path)) {
      throw new IOException(format("Directory '%s' is a symbolic link", directory));
    }
    if (directory.isFile()) {
      throw new IOException(format("Directory '%s' is a file", directory));
    }
    deleteDirectoryImpl(path);

    if (directory.exists()) {
      throw new IOException(format("Unable to delete directory '%s'", directory));
    }
  }
661303
protected function emptyDirectory($directory)
    {
        foreach ($this->doListContents($directory, true) as $path) {
            $this->deletePath($path);
        }
    }
899475
public static boolean delete(File d) {
        if (null == d || !d.exists())
            return true; // by definition

        if (d.isDirectory()) {
            File[] files = d.listFiles(); // and directories
            if (null != files) {
                for (File f : files) {
                    if (f.isDirectory()) {
                        delete(f);
                    } else {
                        f.delete();
                    }
                }
            }
        }
        return d.delete();
    }
343321
function _emptyDirectoryProm (directory) {

			return new Promise((resolve, reject) => {

				readdir(directory, (err, files) => {
					return err ? reject(err) : resolve(files);
				});

			}).then((files) => {

				const result = [];

					for (let i = 0; i < files.length; ++i) {
						result.push(join(directory, files[i]));
					}

				return Promise.resolve(result);

			}).then((files) => {
				return files.length ? _removeDirectoryContentProm(files) : Promise.resolve();
			});

		}
225566
public static boolean deleteFile(final File file) {
		// delete directory content recursively
		if (file.isDirectory()) {
			final File[] children = file.listFiles();
			for (File child : children) {
				if (!deleteFile(child)) {
					return false;
				}
			}
		}

		// delete file/empty directory
		return file.delete();
	}