remove directory recursivly (all items within)
12305
async function rmrf(dir){
    // get absolute path
    const absPath = _path.resolve(dir);

    let stats = null;
    // stats command executable ? dir/file exists
    try{
        stats = await _fs.stat(absPath);

    }catch(e){
        throw new Error('Requested directory <' + absPath  + '> does not exists or is not accessible');
    }

    // split path into components
    const dirComponents = _path.parse(absPath);

    // get root dir (posix + windows)
    const rootDir = dirComponents.root;

    // extract dir (without root)
    const dirRelativePath = _path.join(dirComponents.dir, dirComponents.base).substring(rootDir.length);

    // split into parts
    const subdirs = dirRelativePath.split(_path.sep);

    // minimum of 1 segement required - this function does not remove directories within filesystem root
    if (subdirs.length < 2){
        throw Error('Recursive rm does not remove directories within filesystem root! This is a security consideration!');
    }
    
    // check if its a directory
    if (!stats.isDirectory()){
        // just remove the item
        await _fs.unlink(absPath);
        return;
    }

    // get all items of given directory
    const [files, dirs] = await _fs.scandir(absPath, true, true);

    // delete all files
    // @TODO this can be done in parallel with Promise.all but should limited
    // to a maximum amount of calls (limited file handles!)
    for (let i=0;i<files.length;i++){
        await _fs.unlink(files[i]);
    }

    // sort directories descending (deepest dirs first)
    dirs.sort().reverse();

    // delete all dirs
    for (let i=0;i<dirs.length;i++){
        await _fs.rmdir(dirs[i]);
    }

    // finally delete base dir
    await _fs.rmdir(absPath);
}
724602
def clean_directories(builddir, in_dir=True, out_dir=True):
    """"""
    container_in = local.path(builddir) / "container-in"
    container_out = local.path(builddir) / "container-out"

    if in_dir and container_in.exists():
        if ui.ask("Should I delete '{0}'?".format(container_in)):
            container_in.delete()
    if out_dir and container_out.exists():
        if ui.ask("Should I delete '{0}'?".format(container_out)):
            container_out.delete()
1065931
def remove(self):
        

        directory = self._directory()
        assert isinstance(directory, Directory)
        directory._fileDeleted(self)
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)
1210071
function() {
        var items = _utils.getArgArray(arguments);
        if (items.length === 0) {
            throw new Error('no files specified to clean up');
        }
        items.forEach(function(item) {
            try {
                var path = (typeof item === 'string') ? item : item.path;
                _fs.unlinkSync(path);
            } catch (e) {
                // Eat the exception.
            }
        });
    }
998675
def reset_directory(directory):
    
    if os.path.isdir(directory): shutil.rmtree(directory)
    if not os.path.isdir(directory): os.makedirs(directory)
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
66962
def _clean_directory(self, name):
        """"""
        if not os.path.exists(name):
            return
        self.announce(
            "removing directory '{}' and all its contents".format(name)
        )
        if not self.dry_run:
            rmtree(name, True)
615666
def remove_blank_dirs(self):
        """"""
        if self.is_blank():
            try:
                os.rmdir(self.path)
            except OSError as e:
                print(e)
        else:
            remove_empty_dir(self.path)
464190
public static function removeDirectory($directory)
    {
        $inner = new \RecursiveDirectoryIterator($directory, \FilesystemIterator::SKIP_DOTS);
        $outer = new \RecursiveIteratorIterator($inner, \RecursiveIteratorIterator::SELF_FIRST);

        // remove the files first
        foreach ($outer as $file) {
            if ($file->isFile()) {
                unlink($file);
            }
        }

        // remove the sub-directories next
        $files = iterator_to_array($outer);
        foreach (array_reverse($files) as $file) {
            /** @var \SplFileInfo $file */
            if ($file->isDir()) {
                rmdir($file);
            }
        }

        // finally the directory itself
        rmdir($directory);
    }
677218
def rmdir(self, dir_name):
        """"""
        self.check_write(dir_name)
        path = normpath_url(join_url(self.cur_dir, dir_name))
        # write("REMOVE %r" % path)
        shutil.rmtree(path)
1684
def delete(self):
        """"""
        if self.isfile:
            os.remove(self.fn)
        elif self.isdir:
            shutil.rmtree(self.fn)
562362
def rm(filename, recursive=False, force=False):
    """"""
    return auto(remove_file, filename, recursive, force)
14024
def clear(self):
        
        not_removed = []
        for fn in os.listdir(self.base):
            fn = os.path.join(self.base, fn)
            try:
                if os.path.islink(fn) or os.path.isfile(fn):
                    os.remove(fn)
                elif os.path.isdir(fn):
                    shutil.rmtree(fn)
            except Exception:
                not_removed.append(fn)
        return not_removed
315389
def remove(item):
    
    if os.path.isdir(item):
        shutil.rmtree(item)
    else:
        # Assume it's a file. error if not.
        os.remove(item)
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)
742767
def clear_dir(self):
        """"""
        for snapshot in output_utils.get_filenames(self.output_dir):
            if snapshot.endswith('.pkl'):
                os.remove(snapshot)