8.5.x file.inc file_unmanaged_delete($path)
8.0.x file.inc file_unmanaged_delete($path)
8.1.x file.inc file_unmanaged_delete($path)
8.2.x file.inc file_unmanaged_delete($path)
8.3.x file.inc file_unmanaged_delete($path)
8.4.x file.inc file_unmanaged_delete($path)
8.6.x file.inc file_unmanaged_delete($path)
7.x file.inc file_unmanaged_delete($path)

Deletes a file without database changes or hook invocations.

This function should be used when the file to be deleted does not have an entry recorded in the files table.


$path: A string containing a file path or (streamwrapper) URI.

Return value

TRUE for success or path does not exist, or FALSE in the event of an error.

See also



Related topics

10 calls to file_unmanaged_delete()
drupal_delete_file_if_stale in includes/common.inc
Callback to delete files modified more than a set time ago.
FileUnmanagedDeleteTest::testDirectory in modules/simpletest/tests/file.test
Try deleting a directory.
FileUnmanagedDeleteTest::testMissing in modules/simpletest/tests/file.test
Try deleting a missing file.
FileUnmanagedDeleteTest::testNormal in modules/simpletest/tests/file.test
Delete a normal file.
file_unmanaged_delete_recursive in includes/file.inc
Deletes all files and directories in the specified filepath recursively.

... See full list


includes/file.inc, line 1334
API for handling file uploads and server file management.


function file_unmanaged_delete($path) {
  if (is_dir($path)) {
    watchdog('file', '%path is a directory and cannot be removed using file_unmanaged_delete().', array(
      '%path' => $path,
    return FALSE;
  if (is_file($path)) {
    return drupal_unlink($path);

  // Return TRUE for non-existent file, but log that nothing was actually
  // deleted, as the current state is the intended result.
  if (!file_exists($path)) {
    watchdog('file', 'The file %path was not deleted, because it does not exist.', array(
      '%path' => $path,
    return TRUE;

  // We cannot handle anything other than files and directories. Log an error
  // for everything else (sockets, symbolic links, etc).
  watchdog('file', 'The file %path is not of a recognized type so it was not deleted.', array(
    '%path' => $path,
  return FALSE;