{"record":{"id":"09bc321237ac0681","repo":"Unity-Technologies/UnityCsReference","slug":"failed-to-move-file-directory-from-0-to-1","errorCode":null,"errorMessage":"Failed to Move File / Directory from '{0}' to '{1}'.","messagePattern":"Failed to Move File / Directory from '(.+?)' to '(.+?)'\\.","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/FileUtil.bindings.cs","lineNumber":89,"sourceCode":"        }\n\n        [FreeFunction(\"CopyFileOrDirectoryFollowSymlinks\")]\n        private static extern bool CopyFileOrDirectoryFollowSymlinksInternal(string source, string dest);\n\n        // Moves a file or a directory from a given path to another path.\n        public static void MoveFileOrDirectory(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 (!MoveFileOrDirectoryInternal(source, dest))\n            {\n                throw new System.IO.IOException(string.Format(\n                    \"Failed to Move File / Directory from '{0}' to '{1}'.\", source, dest));\n            }\n        }\n\n        [FreeFunction(\"MoveFileOrDirectory\")]\n        private static extern bool MoveFileOrDirectoryInternal(string source, string dest);\n\n        private static void CheckForValidSourceAndDestinationArgumentsAndRaiseAnExceptionWhenNullOrEmpty(string source, string dest)\n        {\n            if (source == null) throw new ArgumentNullException(\"source\");\n            if (dest == null) throw new ArgumentNullException(\"dest\");\n\n            if (source == string.Empty) throw new ArgumentException(\"source\", \"The source path cannot be empty.\");\n            if (dest == string.Empty) throw new ArgumentException(\"dest\", \"The destination path cannot be empty.\");\n        }\n\n        // Returns a unique path in the Temp folder within your current project.\n        [FreeFunction]","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/FileUtil.bindings.cs#L71-L107","documentation":"After the exists-check, MoveFileOrDirectory calls the native MoveFileOrDirectoryInternal; a false return throws System.IO.IOException with 'Failed to Move File / Directory'. Unlike the copy exists-check, this message is correct. False returns map to OS-level move failures: cross-volume moves when the OS cannot fall back to copy+delete, locked source files, permissions, or missing source.","triggerScenarios":"Moving across volumes/devices when the underlying OS move cannot do an atomic rename (and Unity does not auto-fallback). Source file is open/locked by Unity or another process. Source path does not exist. Permissions deny the move.","commonSituations":"Moving Library/ artefacts while the editor holds them open. Moving project files between a system drive and an external/network volume. Antivirus locking newly created files. Moving a folder into one of its own descendants.","solutions":["If moving across volumes, fall back to copy-then-delete (CopyFileOrDirectory then DeleteFileOrDirectory) when the native move fails.","Ensure the source is not locked (close the editor/other processes; disable AV scanning of the path).","Validate source existence and that destination is on the same volume for atomic moves.","Catch IOException and surface the OS error code for diagnosis."],"exampleFix":"// before\nFileUtil.MoveFileOrDirectory(src, dst);\n// after\ntry { FileUtil.MoveFileOrDirectory(src, dst); }\ncatch (System.IO.IOException) {\n  FileUtil.CopyFileOrDirectory(src, dst);\n  FileUtil.DeleteFileOrDirectory(src);\n}","handlingStrategy":"fallback","validationCode":"if (!FileUtil.PathExists(src)) throw new FileNotFoundException(src);\nFileUtil.MoveFileOrDirectory(src, dst);","typeGuard":null,"tryCatchPattern":"try { FileUtil.MoveFileOrDirectory(src, dst); }\ncatch (System.IO.IOException) {\n  // cross-volume or locked: fall back to copy + delete\n  FileUtil.CopyFileOrDirectory(src, dst);\n  FileUtil.DeleteFileOrDirectory(src);\n}","preventionTips":["For cross-volume moves, expect native move to fail and provide a copy+delete fallback.","Close the editor and other processes before moving Library/ artefacts.","Validate source existence and same-volume destination for atomic moves.","Log the OS error to distinguish lock vs permission vs missing source."],"tags":["filesystem","move","ioexception","native-failure","cross-volume","unity-editor"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}