CFile::purge PHP Method

purge() public method

If the current filesystem object is a file its contents set to ''. If the current filesystem object is a directory all its descendants are deleted.
public purge ( null | string $path = null ) : boolean | CFile
$path null | string Filesystem path to object to purge.
return boolean | CFile Current CFile object on success, 'False' on fail.
    public function purge($path = null)
    {
        if (!$path) {
            $path = $this->_realpath;
        }
        if ($this->getIsFile()) {
            if ($this->getWriteable()) {
                $this->setContents('');
                return True;
            }
        } else {
            $this->addLog('Purging directory "' . $path . '"', 'trace');
            $contents = $this->dirContents($path, True);
            foreach ($contents as $item) {
                if (is_file($item)) {
                    @unlink($item);
                } elseif (is_dir($item)) {
                    $this->purge($item);
                    @rmdir($item);
                }
            }
            // TODO hey, still need a valid check here
            return True;
        }
        return False;
    }