Filesystem::delete PHP Method

delete() public static method

public static delete ( $file, $deleteIfNotEmpty = true )
    public static function delete($file, $deleteIfNotEmpty = true)
    {
        if (!self::exists($file)) {
            return false;
        }
        $file = self::path($file);
        if (!self::isDir($file)) {
            return unlink($file);
        } else {
            $dir = rtrim($file, DIRECTORY_SEPARATOR) . '/';
            $files = self::getFiles($dir);
            if (!count($files)) {
                return rmdir($dir);
            } else {
                if (!$deleteIfNotEmpty) {
                    return true;
                }
                foreach ($files as $each) {
                    self::delete($each);
                }
                return self::delete($dir);
            }
        }
    }

Usage Example

Esempio n. 1
0
 public function tearDown()
 {
     try {
         $this->filesystem->delete('file.txt');
     } catch (FileNotFoundException $e) {
     }
     $this->filesystem->deleteDir('files');
 }
All Usage Examples Of Filesystem::delete