{"record":{"id":"c08b0d00ab545d09","repo":"Unity-Technologies/UnityCsReference","slug":"failed-to-copy-file-directory-from-0-to-1-c08b0d","errorCode":null,"errorMessage":"Failed to Copy File / Directory from '{0}' to '{1}'.","messagePattern":"Failed to Copy File / Directory from '(.+?)' to '(.+?)'\\.","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/FileUtil.bindings.cs","lineNumber":47,"sourceCode":"        private static extern bool DeleteFileOrDirectoryInternal(string path);\n\n        [FreeFunction(\"IsPathCreated\")]\n        private static extern bool PathExists(string path);\n\n        // Copies a file or directory.\n        public static void CopyFileOrDirectory(string source, string dest)\n        {\n            CheckForValidSourceAndDestinationArgumentsAndRaiseAnExceptionWhenNullOrEmpty(source, dest);\n\n            if (PathExists(dest))\n            {\n                throw new System.IO.IOException(string.Format(\n                    \"Failed to Copy File / Directory from '{0}' to '{1}': destination path already exists.\", source, dest));\n            }\n\n            if (!CopyFileOrDirectoryInternal(source, dest))\n            {\n                throw new System.IO.IOException(string.Format(\n                    \"Failed to Copy File / Directory from '{0}' to '{1}'.\", source, dest));\n            }\n        }\n\n        [FreeFunction(\"CopyFileOrDirectory\")]\n        private static extern bool CopyFileOrDirectoryInternal(string source, string dest);\n\n        // Copies the file or directory following symbolic links.\n        public static void CopyFileOrDirectoryFollowSymlinks(string source, string dest)\n        {\n            CheckForValidSourceAndDestinationArgumentsAndRaiseAnExceptionWhenNullOrEmpty(source, dest);\n\n            if (PathExists(dest))\n            {\n                throw new System.IO.IOException(string.Format(\n                    \"Failed to Copy File / Directory from '{0}' to '{1}': destination path already exists.\", source, dest));\n            }\n","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/FileUtil.bindings.cs#L29-L65","documentation":"After the destination-exists check passes, CopyFileOrDirectory invokes the native CopyFileOrDirectoryInternal; if it returns false the method throws System.IO.IOException with the generic 'Failed to Copy' message. A false return from the native side signals a low-level OS error (permissions, locked file, missing source, path-too-long, I/O fault) that the managed layer does not classify further.","triggerScenarios":"Source path does not exist or is inaccessible; destination volume is read-only or out of space; the source file is locked by another process; the path exceeds platform limits; a symlink loop. Any condition where the native copy returns false.","commonSituations":"Copying from a Library/ path that Unity has locked. Copying onto a network mount with intermittent permissions. Path longer than MAX_PATH on Windows. Source deleted between the PathExists check on dest and the copy call.","solutions":["Verify the source exists and is readable (FileUtil.PathExists(src)) before copying.","Check destination volume writability and free space; close other programs holding the file.","On Windows, shorten long paths or enable long-path support.","Wrap in try/catch IOException and surface the OS error / retry with back-off for transient locks."],"exampleFix":"// before\nFileUtil.CopyFileOrDirectory(src, dst);\n// after\nif (!FileUtil.PathExists(src)) throw new FileNotFoundException(src);\ntry { FileUtil.CopyFileOrDirectory(src, dst); }\ncatch (System.IO.IOException ex) { Debug.LogError($\"copy failed: {ex.Message}\"); throw; }","handlingStrategy":"try-catch","validationCode":"if (!FileUtil.PathExists(src)) throw new FileNotFoundException(src);\n// ensure target volume writable/free, then:\nFileUtil.CopyFileOrDirectory(src, dst);","typeGuard":null,"tryCatchPattern":"try { FileUtil.CopyFileOrDirectory(src, dst); }\ncatch (System.IO.IOException ex)\n{ Debug.LogError($\"native copy failed for {src} -> {dst}: {ex.Message}\"); throw; }","preventionTips":["Verify source existence and readability before copying.","Ensure the destination volume has free space and is writable.","Close/quit other programs holding the source file; exclude paths from AV scanning.","Shorten long Windows paths or enable long-path support."],"tags":["filesystem","copy","ioexception","native-failure","unity-editor"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}