Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. FileSystem.php

function FileSystem::delete

Overrides FileSystemInterface::delete

1 call to FileSystem::delete()
FileSystem::deleteRecursive in core/lib/Drupal/Core/File/FileSystem.php
Deletes all files and directories in the specified filepath recursively.

File

core/lib/Drupal/Core/File/FileSystem.php, line 316

Class

FileSystem
Provides helpers to operate on files and stream wrappers.

Namespace

Drupal\Core\File

Code

public function delete($path) {
    if (is_file($path)) {
        if (!$this->unlink($path)) {
            throw new FileException("Failed to unlink file '{$path}'.");
        }
        return TRUE;
    }
    if (is_dir($path)) {
        throw new NotRegularFileException("Cannot delete '{$path}' because it is a directory. Use deleteRecursive() instead.");
    }
    // Return TRUE for non-existent file as the current state is the intended
    // result.
    if (!file_exists($path)) {
        return TRUE;
    }
    // We cannot handle anything other than files and directories.
    // Throw an exception for everything else (sockets, symbolic links, etc).
    throw new NotRegularFileException("The file '{$path}' is not of a recognized type so it was not deleted.");
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal