Remove dirs/files

@param array  command arguments
@return array
@author Dmitry (dio) Levashov
326278
protected function rm($args) {
		$targets = is_array($args['targets']) ? $args['targets'] : array();
		$result  = array('removed' => array());
		
		foreach ($targets as $target) {
			if (($volume = $this->volume($target)) == false) {
				$result['warning'] = $this->error(self::ERROR_RM, '#'.$target, self::ERROR_FILE_NOT_FOUND);
				return $result;
			}
			if (!$volume->rm($target)) {
				$result['warning'] = $this->error($volume->error());
				return $result;
			}
		}

		return $result;
	}
539731
public function remove(array $RemoveFiles = [])
    {
        /// Convert all paths in base64
        $removedFiles_b64 = $this->encodePaths($RemoveFiles);

        $result = $this->callService('POST', self::API_FS_RM, [
            'files' => $removedFiles_b64,
        ]);

        return $result->getModel(models\FileSystem\FsTask::class);
    }
1276662
function removeFile(files) {
  return [].concat(files).map(file =>
    new Promise((resolve, reject) => {
      fs.unlink(file, (err) => {
        if (err && err.code !== 'ENOENT') reject(err);
        resolve();
      });
    }));
}
1237289
function cleanup($args)
    {
        // $_SESSION['compose']['attachments'] is not a complete record of
        // temporary files because loading a draft or starting a forward copies
        // the file to disk, but does not make an entry in that array
        if (is_array($_SESSION['plugins']['filesystem_attachments'])) {
            foreach ($_SESSION['plugins']['filesystem_attachments'] as $group => $files) {
                if ($args['group'] && $args['group'] != $group) {
                    continue;
                }

                foreach ((array)$files as $filename) {
                    if (file_exists($filename)) {
                        unlink($filename);
                    }
                }

                unset($_SESSION['plugins']['filesystem_attachments'][$group]);
            }
        }
        return $args;
    }
889901
public function delete()
    {
        $report = array();
        $options = func_get_args();
        $options = array_combine(
            array_filter($options, function ($v) {return (bool) $v&2;}),
            array_filter($options, function ($v) {return (bool) ($v-1)&2;})
        );

        // exact matching
        if (isset($options[PCLZIP_OPT_BY_NAME]))
            $selectFilter = function ($key, $value) use ($options) {
                $allowedNames = is_array($options[PCLZIP_OPT_BY_NAME])
                    ? $options[PCLZIP_OPT_BY_NAME]
                    : explode(',', $options[PCLZIP_OPT_BY_NAME]);
                foreach ($allowedNames as $name) {
                    // select directory with nested files
                    if (in_array(substr($name, -1), array('/', '\\'))) {
                        if (strncasecmp($name, $key, strlen($name)) === 0) {
                            // that's a file inside a dir or that dir
                            return self::SELECT_FILTER_PASS;
                        }
                    } else {
                        // select exact name only
                        if (strcasecmp($name, $key) === 0) {
                            // that's a file with this name
                            return self::SELECT_FILTER_PASS;
                        }
                    }
                }

                // that file is not in allowed list
                return self::SELECT_FILTER_REFUSE;
            };
        // <ereg> rule
        else if (isset($options[PCLZIP_OPT_BY_EREG]) && function_exists('ereg'))
            $selectFilter = function ($key, $value) use ($options) {
                return (ereg($options[PCLZIP_OPT_BY_EREG], $key) !== false)
                    ? self::SELECT_FILTER_PASS
                    : self::SELECT_FILTER_REFUSE;
            };
        // <preg_match> rule
        else if (isset($options[PCLZIP_OPT_BY_PREG]))
            $selectFilter = function ($key, $value) use ($options) {
                return preg_match($options[PCLZIP_OPT_BY_PREG], $key)
                    ? self::SELECT_FILTER_PASS
                    : self::SELECT_FILTER_REFUSE;
            };
        // index rule
        else if (isset($options[PCLZIP_OPT_BY_INDEX]))
            $selectFilter = function ($key, $value, $index) use ($options) {
                $allowedIndexes = array();
                foreach ($options[PCLZIP_OPT_BY_INDEX] as $rule) {
                    $parts = explode('-', $rule);
                    if (count($parts) == 1) $allowedIndexes[] = $rule;
                    else $allowedIndexes = array_merge(
                        range($parts[0], $parts[1]), $allowedIndexes);
                }

                return in_array($index, $allowedIndexes)
                    ? self::SELECT_FILTER_PASS
                    : self::SELECT_FILTER_REFUSE;
            };
        // no rule
        else
            $selectFilter = function () { return self::SELECT_FILTER_PASS; };

        foreach ($this->listContent() as $file_header) {
            // select by select rule
            if (call_user_func($selectFilter, $file_header->stored_filename,
                    $file_header->filename, $file_header->index)
                === self::SELECT_FILTER_REFUSE) {
                // delete file from archive
                if ($this->archive->deleteName($file_header->stored_filename)) {
                    // ok
                    continue;
                }
                // deletion fails
                else {
                    return 0;
                }
            }
            // unselected file add in report
            $report[] = $file_header;
        }

        return $report;
    }
1276806
function deleteFiles(files) {
	_.castArray(files).forEach(file => {
		if (!fs.existsSync(file)) {
			return;
		}

		log.removed(`Delete ${file}`);
		fs.removeSync(file);
	});
}
889530
public static function removeDirectories($directories = null)
	{
		if (is_null($directories))
		{
			static::$directories = array();
		}
		else
		{
			static::$directories = array_diff(static::$directories, (array) $directories);
		}
	}
1345616
protected function deletingFilesNamesList($files) : array
	{
		return $files->flatMap(function($item) {
			$path_parts = pathinfo($item);
			$result[] = $path_parts['filename'];

			return $result;
		})->filter(function($item) {
			return trim($item) != '';
		})->all();
	}
226640
public function remove($items, $dirPath = null, $removeEmptyDirs = false)
    {
        if (!is_array($items)) {
            $items = (array) $items;
        }

        $removeList = array();
        $permissionDeniedList = array();
        foreach ($items as $item) {
            if (isset($dirPath)) {
                $item = Utils\Util::concatPath($dirPath, $item);
            }

            if (!file_exists($item)) {
                continue;
            }

            $removeList[] = $item;

            if (!is_writable($item)) {
                $permissionDeniedList[] = $item;
            } else if (!is_writable(dirname($item))) {
                $permissionDeniedList[] = dirname($item);
            }
        }

        if (!empty($permissionDeniedList)) {
            $betterPermissionList = $this->getPermissionUtils()->arrangePermissionList($permissionDeniedList);
            throw new Error("Permission denied for <br>". implode(", <br>", $betterPermissionList));
        }

        $result = true;
        foreach ($removeList as $item) {
            if (is_dir($item)) {
                $result &= $this->removeInDir($item, true);
            } else {
                $result &= $this->removeFile($item);
            }

            if ($removeEmptyDirs) {
                $result &= $this->removeEmptyDirs($item);
            }
        }

        return (bool) $result;
    }
987825
public function deleteFiles(array $files) : bool
    {
        if (empty($files)) {
            return false;
        }

        $status = true;

        foreach ($files as $file) {
            if (file_exists($file)) {
                $status = $status && unlink($file);
            }
        }

        return $status;
    }
680451
public function removeFile($filePaths, $dirPath = null)
    {
        if (!is_array($filePaths)) {
            $filePaths = (array) $filePaths;
        }

        $result = true;
        foreach ($filePaths as $filePath) {
            if (isset($dirPath)) {
                $filePath = Utils\Util::concatPath($dirPath, $filePath);
            }

            if (file_exists($filePath) && is_file($filePath)) {
                if (function_exists('opcache_invalidate')) {
                    @opcache_invalidate($filePath, true);
                }
                $result &= unlink($filePath);
            }
        }

        return $result;
    }
924677
protected function cleanDirectory($directory, $maxAge = null, $keepMax = 5, array $blacklist = [], $quiet = true)
    {
        if (!is_dir($directory)) {
            return [0, 0];
        }
        $files = glob($directory . '/*');
        if (!$files) {
            return [0, 0];
        }
        // Sort files by modified time (descending).
        usort(
            $files,
            function ($a, $b) {
                return filemtime($a) < filemtime($b);
            }
        );
        $now = time();
        $numDeleted = 0;
        $numKept = 0;
        foreach ($files as $filename) {
            if (in_array($filename, $blacklist)) {
                $numKept++;
                continue;
            }
            if (($keepMax !== null && $numKept >= $keepMax)
                || ($maxAge !== null && $now - filemtime($filename) > $maxAge)) {
                if (!$quiet) {
                    $this->output->writeln("Deleting: " . basename($filename));
                }
                if ($this->fsHelper->remove($filename)) {
                    $numDeleted++;
                } elseif (!$quiet) {
                    $this->output->writeln("Failed to delete: <error>" . basename($filename) . "</error>");
                }
            } else {
                $numKept++;
            }
        }

        return [$numDeleted, $numKept];
    }
391004
function removeCommandsDirectory(string $path) {
        $path = \realpath($path);
        if($path === false) {
            throw new \InvalidArgumentException('Invalid path specified');
        }
        
        $pos = \array_search($path, $this->commandsDirectories, true);
        if($pos !== false) {
            unset($this->commandsDirectories[$pos]);
        }
        
        return $this;
    }
801646
public function pruneAll()
    {
        $files = glob($this->config['basepath'] . '/*');
        $items = count($files);
        array_map('unlink', $files);
        return $items;
    }
999047
public function clear()
    {
        $result = true;
        $dir = new \DirectoryIterator($this->path);
        foreach ($dir as $file) {
            $extension = pathinfo($file->getFilename(), PATHINFO_EXTENSION);
            if (!$file->isDot() && $extension === 'ser') {
                if (!@unlink($this->path.'/'.$file->getFilename())) {
                    $result = false;
                }
            }
        }

        return $result;
    }
1147421
public function purge($dir)
    {
        if (!is_dir($dir)) {
            return;
        }

        $files = scandir($dir);

        if ($files !== false) {
            foreach ($files as $file) {
                if ($file === '.' || $file === '..') {
                    continue;
                }

                $path = $dir . '/' . $file;

                if (is_dir($path)) {
                    $this->purge($path);
                    rmdir($path);
                } else {
                    unlink($path);
                }
            }
        }
    }
634814
public function delTree($dir)
    {
        if (! file_exists($dir)) {
            return false;
        }

        $files = array_diff(scandir($dir), ['.', '..']);

        $this->deleteAllFiles($dir, $files);

        return rmdir($dir);
    }