Nette\Utils\FileSystem::delete PHP Method

delete() public static method

Deletes a file or directory.
public static delete ( $path ) : void
return void
    public static function delete($path)
    {
        if (is_file($path) || is_link($path)) {
            $func = DIRECTORY_SEPARATOR === '\\' && is_dir($path) ? 'rmdir' : 'unlink';
            if (!@$func($path)) {
                // @ is escalated to exception
                throw new Nette\IOException("Unable to delete '{$path}'.");
            }
        } elseif (is_dir($path)) {
            foreach (new \FilesystemIterator($path) as $item) {
                static::delete($item->getPathname());
            }
            if (!@rmdir($path)) {
                // @ is escalated to exception
                throw new Nette\IOException("Unable to delete directory '{$path}'.");
            }
        }
    }

Usage Example

コード例 #1
0
 private function createAndReturnTempDir() : string
 {
     $tempDir = sys_get_temp_dir() . '/php7_codesniffer';
     FileSystem::delete($tempDir);
     FileSystem::createDir($tempDir);
     return $tempDir;
 }
All Usage Examples Of Nette\Utils\FileSystem::delete