Removes files given the path and optionally a regular expression

@param string|null regular expression

@return Eden\Folder\Index
8031
public function removeFiles($regex = null)
    {
        //argument 1 must be a string
        Argument::i()->test(1, 'string', 'null');

        //get the files
        $files = $this->getFiles($regex);

        if (empty($files)) {
            return $this;
        }

        //walk the array
        foreach ($files as $file) {
            //remove everything
            $file->remove();
        }

        return $this;
    }
1028455
public function remove($path)
	{
		// Cheap optimisation to direct remove the node if there is no separator
		if (!strpos($path, $this->separator))
		{
			$result = (isset($this->data->$path) && $this->data->$path !== null && $this->data->$path !== '') ? $this->data->$path : null;

			unset($this->data->$path);

			return $result;
		}

		/*
		 * Explode the registry path into an array and remove empty
		 * nodes that occur as a result of a double separator. ex: joomla..test
		 * Finally, re-key the array so they are sequential.
		 */
		$nodes = array_values(array_filter(explode($this->separator, $path), 'strlen'));

		if (!$nodes)
		{
			return;
		}

		// Initialize the current node to be the registry root.
		$node   = $this->data;
		$parent = null;

		// Traverse the registry to find the correct node for the result.
		for ($i = 0, $n = \count($nodes) - 1; $i < $n; $i++)
		{
			if (\is_object($node))
			{
				if (!isset($node->{$nodes[$i]}) && ($i !== $n))
				{
					continue;
				}

				$parent = &$node;
				$node   = $node->{$nodes[$i]};

				continue;
			}

			if (\is_array($node))
			{
				if (($i !== $n) && !isset($node[$nodes[$i]]))
				{
					continue;
				}

				$parent = &$node;
				$node   = $node[$nodes[$i]];

				continue;
			}
		}

		// Get the old value if exists so we can return it
		switch (true)
		{
			case \is_object($node):
				$result = isset($node->{$nodes[$i]}) ? $node->{$nodes[$i]} : null;
				unset($parent->{$nodes[$i]});

				break;

			case \is_array($node):
				$result = isset($node[$nodes[$i]]) ? $node[$nodes[$i]] : null;
				unset($parent[$nodes[$i]]);

				break;

			default:
				$result = null;

				break;
		}

		return $result;
	}
1027738
private function removeDirectory(string $path): bool
    {
        $iterator = new DirectoryIterator($path);
        foreach ($iterator as $fileInfo) {
            if ($fileInfo->isDot() || !$fileInfo->isDir()) {
                continue;
            }
            $dirName = $fileInfo->getPathname();
            $this->removeDirectory($dirName);
        }

        $files = new FilesystemIterator($path);

        /** @var SplFileInfo $file */
        foreach ($files as $file) {
            $fileName = $file->getPathname();
            unlink($fileName);
        }

        return rmdir($path);
    }
306053
public static function purge($path = null, array &$logs = array())
    {
        if (is_null($path)) {
            return null;
        }
        if (file_exists($path) && is_dir($path)) {
            $iterator = new \RecursiveIteratorIterator(
                new \RecursiveDirectoryIterator($path), 
                \RecursiveIteratorIterator::SELF_FIRST | \FilesystemIterator::CURRENT_AS_FILEINFO | \FilesystemIterator::SKIP_DOTS
            );
            foreach ($iterator as $item) {
                if (in_array($item->getFilename(), array('.', '..'))) {
                    continue;
                }
                $_path = $item->getRealpath();
                if (array_key_exists($_path, $logs)) {
                    return false;
                }
                if ($item->isDir()) {
                    if (false===($ok = self::remove($_path, $logs))) {
                        $logs[$_path] = sprintf('Can not remove diretory "%s".', $_path);
                    }
                } else {
                    if (false===($ok = File::remove($_path, $logs))) {
                        $logs[$_path] = sprintf('Can not unlink file "%s".', $_path);
                    }
                }
            } 
            clearstatcache();
            return $ok;
        } else {
            $logs[$path] = sprintf('Directory "%s" not found.', $path);
        }
        return false;
    }
751158
@Nonnull
    public static String normalizeFolder(@Nullable String path) {
        if (path == null) {
            path = "";
        } else {
            path = normalizeFile(path, null);
        }
        if (!path.endsWith("/")) {
            path = path + "/";
        }
        return path;
    }
496299
public function find($paths = null)
    {
        if ($paths === null) $paths = $this->paths;

        // iterator
        $iterator = $this->getIterator();

        // search in target paths
        foreach ((array)$paths as $path) {
            $this->searchInPath($iterator, $path);
        }

        // clear
        $this->clear();

        return $iterator;
    }
533481
public static function clean_path($path)
	{
		static $search = array(APPPATH, COREPATH, PKGPATH, DOCROOT, '\\');
		static $replace = array('APPPATH/', 'COREPATH/', 'PKGPATH/', 'DOCROOT/', '/');
		return str_ireplace($search, $replace, $path);
	}
1374212
public static function delete($path)
    {
        $files = self::getContent($path);
        foreach ($files as $file) {
            if (is_dir($path.DIRECTORY_SEPARATOR.$file)) {
                self::delete($path.DIRECTORY_SEPARATOR.$file);
            } else {
                @unlink($path.DIRECTORY_SEPARATOR.$file);
            }
        }

        return @rmdir($path);
    }
1305471
public static function file($index = null, $default = null)
	{
		return (func_num_args() === 0) ? $_FILES : \Arr::get($_FILES, $index, $default);
	}
814223
protected function clean($path)
    {
        $path = rtrim($path, ' /\\');

        $path = str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $path);

        return $path;
    }
650246
public static function RemoveWorkingDir( string $path = null ) : string
   {

      if ( \is_null( $path ) )
      {
         return '';
      }

      $wd = '~^' . \preg_quote( static::Unixize( \getcwd() ) . '/' ) . '~';

      return \preg_replace( $wd, '', static::Unixize( $path ) );

   }
1154768
public function cleanThumbnails($path = '')
    {
        $cleanPathInfo = new SplFileInfo(realpath($this->getDocumentRoot() . DIRECTORY_SEPARATOR . $path));

        if (strpos($cleanPathInfo->getRealPath(), $this->getDocumentRoot()) === 0) {
            if ($cleanPathInfo->isDir()) {
                // Clean thumbnails in specified directory
                $dirIterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($cleanPathInfo->getRealPath()), RecursiveIteratorIterator::SELF_FIRST);

                foreach ($dirIterator as $path => $splFileObject) {
                    /* @var SplFileObject $splFileObject */
                    if (!in_array($splFileObject->getBasename(), ['.', '..'])
                        && preg_match('#.*-' . $this->getThumbnailPrefix() . '-([\w\d]+)\.(' . implode('|', $this->getAllowedExtensions()) . ')$#', $splFileObject->getBasename())
                    ) {
                        unlink($splFileObject->getRealPath());
                    }
                }

                return true;

            } elseif ($cleanPathInfo->isFile() && in_array($cleanPathInfo->getExtension(), $this->getAllowedExtensions())) {
                // Clean thumbnails for one image
                $imagePathRemExt = $cleanPathInfo->getPath() . DIRECTORY_SEPARATOR . $cleanPathInfo->getBasename('.' . $cleanPathInfo->getExtension());

                $thumbnails = glob($imagePathRemExt . '-' . $this->getThumbnailPrefix() . '-*');
                foreach ($thumbnails as $thumbnailPath) {
                    unlink($thumbnailPath);
                }

                return true;
            }
        }

        return false;
    }
1237536
public static function purifyPath($path)
    {
        $path = (string)$path;
        $path = trim($path);
        $path = rtrim($path, '\\/');

        return $path;
    }
94350
public function execute($path = null)
    {
        $content = '';

        // loop files
        foreach ($this->data as $source => $js) {
            /*
             * Combine js: separating the scripts by a ;
             * I'm also adding a newline: it will be eaten when whitespace is
             * stripped, but we need to make sure we're not just appending
             * a new script right after a previous script that ended with a
             * singe-line comment on the last line (in which case it would also
             * be seen as part of that comment)
             */
            $content .= $js."\n;";
        }

        /*
         * Let's first take out strings, comments and regular expressions.
         * All of these can contain JS code-like characters, and we should make
         * sure any further magic ignores anything inside of these.
         *
         * Consider this example, where we should not strip any whitespace:
         * var str = "a   test";
         *
         * Comments will be removed altogether, strings and regular expressions
         * will be replaced by placeholder text, which we'll restore later.
         */
        $this->extractStrings('\'"`');
        $this->stripComments();
        $this->extractRegex();
        $content = $this->replace($content);

        $content = $this->propertyNotation($content);
        $content = $this->shortenBools($content);
        $content = $this->stripWhitespace($content);

        /*
         * Earlier, we extracted strings & regular expressions and replaced them
         * with placeholder text. This will restore them.
         */
        $content = $this->restoreExtractedData($content);

        return $content;
    }
182223
public function emptyDir($remove = false, $path = null)
    {
        if (null === $path) {
            $path = $this->path;
        }
        // Get a directory handle.
        if (!$dh = @opendir($path)) {
            return;
        }

        // Recursively dig through the directory, deleting files where applicable.
        while (false !== ($obj = readdir($dh))) {
            if ($obj == '.' || $obj == '..') {
                continue;
            }
            if (!@unlink($path . DIRECTORY_SEPARATOR . $obj)) {
                $this->emptyDir(true, $path . DIRECTORY_SEPARATOR . $obj);
            }
        }

        // Close the directory handle.
        closedir($dh);

        // If the delete flag was passed, remove the top level directory.
        if ($remove) {
            @rmdir($path);
        }
    }
748794
protected function _prepareFilePath($path = null) {
		if (empty($path)) {
			return false;
		}

		if (DIRECTORY_SEPARATOR !== '\\') {
			return $path;
		}

		$path = str_replace('\\', '/', $path);

		return $path;
	}
347088
protected function removeChildDirecotries(string $dir = null)
    {
        if (empty($dir)) {
            $dir = $this->cacheDir;
        }

        $success = true;
        $objects = new GlobIterator($dir);

        foreach ($objects as $object) {
            if (!is_dir("$dir/$object") && is_link("$dir/$object")) {
                $success = $this->recursiveRemove("$dir/$object") && rmdir($dir) && $success;
            }
        }

        return $success;
    }