removes empty dirs under a given path
420141
def remove_empty_dirs(path):
    
    for root, dirs, files in os.walk(path):
        for d in dirs:
            dir_path = os.path.join(root, d)
            if not os.listdir(dir_path):
                os.rmdir(dir_path)
1305855
public function emptyFolders($path = null) {
		if ($path) {
			$path = realpath($path);
		}
		if (!$path) {
			$path = ROOT . DS;
		}

		$this->out('Clearing empty folders in ' . $path);

		$this->_clearEmpty($path);
	}
1102417
def purge(path: str, pattern: str) -> None:
    
    for f in find(pattern, path):
        log.info("Deleting {}", f)
        os.remove(f)
884680
def clean_extra(self):
        """"""
        extra_paths = self.get_extra_paths()
        for path in extra_paths:
            if not os.path.exists(path):
                continue
            if os.path.isdir(path):
                self._clean_directory(path)
            else:
                self._clean_file(path)
876337
def cleanup_tmpdir(dirname):
    """"""
    if dirname is not None and os.path.exists(dirname):
        shutil.rmtree(dirname)
1095772
def rm_files_in_dir(path):
    
    for f in os.listdir(path):
        try:
            os.remove(f)
        except PermissionError:
            os.chmod(f, 0o777)
            try:
                os.remove(f)
            except Exception:
                pass
    return
138171
def clean_path(root, path, subdir=False):
    '''
    
    '''
    if not os.path.isabs(root):
        return ''
    if not os.path.isabs(path):
        path = os.path.join(root, path)
    path = os.path.normpath(path)
    if subdir:
        if path.startswith(root):
            return path
    else:
        if os.path.dirname(path) == os.path.normpath(root):
            return path
    return ''
1368760
function (path) {
    var pathSep = require('path').sep;
    var dirs = path.split(pathSep);
    var root = '';

    while (dirs.length > 0) {
      var dir = dirs.shift();
      if (dir === '') {
        root = pathSep;
      }
      if (!fs.existsSync(root + dir)) {
        fs.mkdirSync(root + dir);
      }
      root += dir + pathSep;
    }
  }
738278
def _recursive_remove(fs, path):
    
    if not fs.is_link(path=path) and fs.is_dir(path=path):
        for child in fs.children(path=path):
            _recursive_remove(fs=fs, path=child)
        fs.remove_empty_directory(path=path)
    else:
        fs.remove_file(path=path)
316425
private void purgeDirectories(FileSystem fs, Path root) throws IOException {
    DirectoryTraversal traversal =
        DirectoryTraversal.directoryRetriever(Arrays.asList(root), fs,
            directoryTraversalThreads, directoryTraversalShuffle);
    String prefix = root.toUri().getPath();
    
    FileStatus dir;
    while ((dir = traversal.next()) != DirectoryTraversal.FINISH_TOKEN) {
      Path dirPath = dir.getPath();
      if (dirPath.toUri().getPath().endsWith(RaidNode.HAR_SUFFIX)) {
        continue;
      }
      String dirStr = dirPath.toUri().getPath();
      if (!dirStr.startsWith(prefix)) {
        continue;
      }
      entriesProcessed.incrementAndGet();
      String src = dirStr.replaceFirst(prefix, "");
      if (src.length() == 0) continue;
      Path srcPath = new Path(src);
      if (!fs.exists(srcPath)) {
        performDelete(fs, dirPath, true);
      }
    }
  }
912940
function cleanup (dirs) {
  return function (mode, pass, callback) {
    var done = after(dirs.length, callback)

    dirs.forEach(function (dir) {
      rimraf(dir, done)
    })
  }
}
197483
def prune(self, dir):
        """"""
        match = translate_pattern(os.path.join(dir, '**'))
        return self._remove_files(match.match)
537313
static function delete_empty_dir($dir)
    {
        $dir = self::makeVirtualDir($dir, false);
        if (is_dir($dir) && sizeof(scandir($dir)) == 2){
            return @rmdir($dir);
        }
        self::deleteVirtualDir($dir);
        return false;
    }
1062866
def _recurse(self, path):
        '''
        
        '''
        files = {}
        empty_dirs = []
        try:
            sub_paths = os.listdir(path)
        except OSError as exc:
            if exc.errno == errno.ENOENT:
                # Path does not exist
                sys.stderr.write('{0} does not exist\n'.format(path))
                sys.exit(42)
            elif exc.errno in (errno.EINVAL, errno.ENOTDIR):
                # Path is a file (EINVAL on Windows, ENOTDIR otherwise)
                files[path] = self._mode(path)
        else:
            if not sub_paths:
                empty_dirs.append(path)
            for fn_ in sub_paths:
                files_, empty_dirs_ = self._recurse(os.path.join(path, fn_))
                files.update(files_)
                empty_dirs.extend(empty_dirs_)

        return files, empty_dirs
1299838
def empty_directory(self):
        """"""
        for child in self.walkfiles():
            child.remove()
        for child in reversed([d for d in self.walkdirs()]):
            if child == self or not child.isdir():
                continue
            child.rmdir()
265082
def remove_unused_directories(src_folder, categories):
  
  files = os.listdir(src_folder)
  os.mkdir("unused")
  for name in files:
    full_path = os.path.join(src_folder, name)
    if os.path.isdir(full_path):
      if not( name in categories or name == "_background_noise_"):
        newPath = os.path.join("unused", name)
        print("moving: ", full_path, "-->", newPath)
        shutil.move(full_path, newPath)
1177880
def remove(path):
    
    if os.path.isdir(path):
        return __rmtree(path)
    else:
        return __rmfile(path)