Removes a storage directory.

@param dir storage directory to be removed
197518
public void removeDir(StorageDir dir) {
    // TODO(feng): Add a command for manually removing directory
    try (LockResource r = new LockResource(mMetadataWriteLock)) {
      String tierAlias = dir.getParentTier().getTierAlias();
      dir.getParentTier().removeStorageDir(dir);
      synchronized (mBlockStoreEventListeners) {
        for (BlockStoreEventListener listener : mBlockStoreEventListeners) {
          dir.getBlockIds().forEach(listener::onBlockLost);
          listener.onStorageLost(tierAlias, dir.getDirPath());
        }
      }
    }
  }
663798
public static void recursivelyDeleteDirectoryOnExit(final File directory) {
    Runtime.getRuntime().addShutdownHook(new Thread() {
      @Override
      public void run() {
        try {
          recursivelyDeleteDirectory(directory);
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
    });
  }
853565
public static function clear_directory($directory)
    {
        foreach (scandir($directory) as $file) {
            if ($file !== '.' and $file !== '..') {
                unlink($directory.$file);
            }
        }
    }
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()}");
                    }
                }
            }
        }
    }
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();
    }
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");
    	}
    }
954720
public static function removeDirectory(string $dir, bool $remove = true): void
    {
        if (\is_dir($dir)) {
            $entries = \glob($dir . \DIRECTORY_SEPARATOR . '*', \GLOB_NOSORT);
            
            if (empty($entries)) {
                $entries = [];
            }
            
            foreach ($entries as $tmp) {
                if (\is_dir($tmp)) {
                    self::removeDirectory($tmp);
                } else {
                    if (!@\unlink($tmp)) {
                        throw new \RuntimeException(\sprintf('Could not remove directory "%s" due to failed removal of file "%s"%s', $dir, $tmp, self::getErrorInfo()));
                    }
                }
            }
            
            if ($remove) {
                if (!@\rmdir($dir)) {
                    throw new \RuntimeException(sprintf('Could not remove directory "%s"%s', $dir, self::getErrorInfo(error_get_last())));
                }
            }
        }
        
        \clearstatcache(true);
    }
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);
        }
    }
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
814308
public final void dirRemove(File dir) throws IOException {
		if (dir != null) {
			getLog().debug("Deleting tree: " + dir.toString()); //$NON-NLS-1$
			final LinkedList<File> candidates = new LinkedList<>();
			candidates.add(dir);
			File[] children;
			final BuildContext buildContext = getBuildContext();
			while (!candidates.isEmpty()) {
				final File f = candidates.getFirst();
				getLog().debug("Scanning: " + f); //$NON-NLS-1$
				if (f.isDirectory()) {
					children = f.listFiles();
					if (children != null && children.length > 0) {
						// Non empty directory
						for (final File c : children) {
							getLog().debug("Discovering: " + c); //$NON-NLS-1$
							candidates.push(c);
						}
					} else {
						// empty directory
						getLog().debug("Deleting: " + f); //$NON-NLS-1$
						candidates.removeFirst();
						f.delete();
						buildContext.refresh(f.getParentFile());
					}
				} else {
					// not a directory
					candidates.removeFirst();
					if (f.exists()) {
						getLog().debug("Deleting: " + f); //$NON-NLS-1$
						f.delete();
						buildContext.refresh(f.getParentFile());
					}
				}
			}
			getLog().debug("Deletion done"); //$NON-NLS-1$
		}
	}
1350158
function emptyDir(dir) {
  return new Promise((resolve, reject) => {
    FS.emptyDir(dir, err => {
      err ? reject(err) : resolve(dir);
    })
  });
}
309058
private void deleteDir(File dir)
    {
        if (dir.exists() && dir.isDirectory())
        {
            File[] files = dir.listFiles();

            for (int idx = 0; idx < files.length; idx++)
            {
                if (!files[idx].exists())
                {
                    continue;
                }
                if (files[idx].isDirectory())
                {
                    deleteDir(files[idx]);
                }
                else
                {
                    files[idx].delete();
                }
            }
            dir.delete();
        }
    }
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();
		}
    }
788392
public static function rmdirRecursive(string $directory): void
    {
        if (is_dir($directory)) {
            static::emptyDirectory($directory);

            if (!rmdir($directory)) {
                throw new FilesystemException("Unable to remove directory on path={$directory}");
            }
        }
    }
258687
public static void deleteDirectorySilently(final File dir) {
    if (dir != null) {
      try {
        FileUtils.deleteDirectory(dir);
      } catch (final IOException e) {
        log.error("error when deleting dir {}", dir, e);
      }
    }
  }
633504
protected function removeDir($dir){
        foreach (scandir($dir) as $item){
            if ($item == "." || $item == "..")
                continue;

            if (is_dir($item)){
                removeDir($item);
            } else {
                unlink(join(DIRECTORY_SEPARATOR, array($dir, $item)));
            }

        }
        rmdir($dir);
    }
1221189
public static void directoryCheck(String dir) throws IOException {
		final File file = new File(dir);

		if (!file.exists()) {
			FileUtils.forceMkdir(file);
		}
	}