function file_prepare_directory

Same name and namespace in other branches
  1. 7.x includes/ \file_prepare_directory()

Checks that the directory exists and is writable.

Directories need to have execute permissions to be considered a directory by FTP servers, etc.


$directory: A string reference containing the name of a directory path or URI. A trailing slash will be trimmed from a path.

$options: A bitmask to indicate if the directory should be created if it does not exist (FILE_CREATE_DIRECTORY) or made writable if it is read-only (FILE_MODIFY_PERMISSIONS).

Return value

TRUE if the directory exists (or was created) and is writable. FALSE otherwise.


in drupal:8.7.0 and is removed from drupal:9.0.0. Use \Drupal\Core\File\FileSystemInterface::prepareDirectory().

Related topics

2 calls to file_prepare_directory()
FileSystemDeprecationTest::testDeprecatedFilePrepareDirectory in core/tests/Drupal/KernelTests/Core/File/FileSystemDeprecationTest.php
@expectedDeprecation file_prepare_directory() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\File\FileSystemInterface::prepareDirectory(). See
file_unmanaged_prepare in core/includes/
Internal function that prepares the destination for a file_unmanaged_copy or file_unmanaged_move operation.


core/includes/, line 320


function file_prepare_directory(&$directory, $options = FileSystemInterface::MODIFY_PERMISSIONS) {
    @trigger_error('file_prepare_directory() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use \\Drupal\\Core\\File\\FileSystemInterface::prepareDirectory(). See', E_USER_DEPRECATED);
    return \Drupal::service('file_system')->prepareDirectory($directory, $options);

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.