diff --git a/core/includes/file.inc b/core/includes/file.inc
index 83e6dc9..2fde9a2 100644
--- a/core/includes/file.inc
+++ b/core/includes/file.inc
@@ -709,7 +709,7 @@ function file_unmanaged_copy($source, $destination = NULL, $replace = FILE_EXIST
   else {
     // Perhaps $destination is a dir/file?
     $dirname = drupal_dirname($destination);
-    if (!file_prepare_directory($dirname)) {
+    if (!file_prepare_directory($dirname, FILE_CREATE_DIRECTORY)) {
       // The destination is not valid.
       watchdog('file', 'File %file could not be copied because the destination directory %destination is not configured correctly.', array('%file' => $original_source, '%destination' => $dirname));
       drupal_set_message(t('The specified file %file could not be copied because the destination directory is not properly configured. This may be caused by a problem with file or directory permissions. More information is available in the system log.', array('%file' => $original_source)), 'error');
diff --git a/core/modules/system/lib/Drupal/system/Tests/File/UnmanagedCopyTest.php b/core/modules/system/lib/Drupal/system/Tests/File/UnmanagedCopyTest.php
index acae92b..847ff98 100644
--- a/core/modules/system/lib/Drupal/system/Tests/File/UnmanagedCopyTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/File/UnmanagedCopyTest.php
@@ -45,6 +45,11 @@ function testNormal() {
     $this->assertTrue(file_exists($newer_filepath), 'New file exists.');
     $this->assertFilePermissions($newer_filepath, settings()->get('file_chmod_file', FILE_CHMOD_FILE));
 
+    // Make sure file_unmanaged_copy creates the folder structure.
+    $desired_filepath = 'public://inside/folder/' . $this->randomName();
+    $newer_filepath = file_unmanaged_copy($uri, $desired_filepath);
+    $this->assertEqual($newer_filepath, $desired_filepath, 'Folders were created successfully.');
+
     // TODO: test copying to a directory (rather than full directory/file path)
     // TODO: test copying normal files using normal paths (rather than only streams)
   }
