{"record":{"id":"8535ce123ccdd22f","repo":"arduino/Arduino","slug":"unable-to-create-folder-destfile","errorCode":null,"errorMessage":"'Unable to create folder: ' + destFile","messagePattern":"'Unable to create folder: ' \\+ destFile","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"arduino-core/src/processing/app/helpers/FileUtils.java","lineNumber":72,"sourceCode":"      fis = new FileInputStream(source);\n      fos = new FileOutputStream(dest);\n      byte[] buf = new byte[4096];\n      int readBytes = -1;\n      while ((readBytes = fis.read(buf, 0, buf.length)) != -1) {\n        fos.write(buf, 0, readBytes);\n      }\n    } finally {\n      IOUtils.closeQuietly(fis);\n      IOUtils.closeQuietly(fos);\n    }\n  }\n\n  public static void copy(File sourceFolder, File destFolder) throws IOException {\n    for (File file : sourceFolder.listFiles()) {\n      File destFile = new File(destFolder, file.getName());\n      if (file.isDirectory() && !SOURCE_CONTROL_FOLDERS.contains(file.getName())) {\n        if (!destFile.exists() && !destFile.mkdir()) {\n          throw new IOException(\"Unable to create folder: \" + destFile);\n        }\n        copy(file, destFile);\n      } else if (!file.isDirectory()) {\n        copyFile(file, destFile);\n      }\n    }\n  }\n\n  public static void recursiveDelete(File file) {\n    if (file == null) {\n      return;\n    }\n    if (file.isDirectory()) {\n      File[] files = file.listFiles();\n      if (files == null) {\n        return;\n      }\n      for (File current : files) {","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/arduino/Arduino/blob/a0df6e0e83b652c72bc78b0a1376c54d6ebc3bee/arduino-core/src/processing/app/helpers/FileUtils.java#L54-L90","documentation":"FileUtils.copy recursively copies a folder tree and throws IOException \"Unable to create folder: <path>\" when File.mkdir() fails for a needed subdirectory. This typically happens when the destination is not writable, a same-named file already exists, or a parent directory is missing. The message names the exact directory that could not be created.","triggerScenarios":"Calling FileUtils.copy(sourceFolder, destFolder) when a subdirectory destFolder/<name> does not exist and destFile.mkdir() returns false (no write permission on destFolder, a file with the same name exists, or destFolder itself is missing/nonexistent).","commonSituations":"Copying example libraries or sketches into a read-only sketchbook; destination path where a FILE exists with the folder's name; copying into a path whose parent was deleted or not yet created; running without permissions (Program Files on Windows, root-owned dirs on Linux).","solutions":["Check that the destination folder exists and is writable by the current user","Delete/rename any FILE that has the same name as the folder being created","Create parent directories first (destFolder.mkdirs()) before copying","Run with sufficient privileges or choose a writable destination"],"exampleFix":"// before\nFile destFolder = new File(sketchbook, \"libraries/MyLib\");\nFileUtils.copy(src, destFolder);\n// after\nif (!destFolder.exists() && !destFolder.mkdirs()) {\n  throw new IOException(\"Cannot create destination \" + destFolder);\n}\nFileUtils.copy(src, destFolder);","handlingStrategy":"validation","validationCode":"if (!destFolder.isDirectory()) destFolder.mkdirs();\nif (!destFolder.canWrite()) throw new IOException(\"Not writable: \" + destFolder);\nFile probe = new File(destFolder, sourceFolder.listFiles()[0].getName());\nif (probe.exists() && probe.isFile() && sourceFolder.listFiles()[0].isDirectory())\n  throw new IOException(\"File blocks folder: \" + probe);","typeGuard":"boolean canCopyInto(File dest) {\n  return dest != null && (dest.isDirectory() || dest.mkdirs()) && dest.canWrite();\n}","tryCatchPattern":"try {\n  FileUtils.copy(src, dest);\n} catch (IOException e) {\n  if (e.getMessage().startsWith(\"Unable to create folder\"))\n    fixPermissionsOrPath(new File(e.getMessage().replace(\"Unable to create folder: \", \"\")));\n  else throw e;\n}","preventionTips":["Always mkdirs() the destination before copying","Check canWrite() on the destination root","Ensure no files share names with folders being copied","Run installs outside permission-restricted directories"],"tags":["file-io","directory-creation","ioexception","permissions"],"backgroundTag":"mkdir-permission-denied","analyzedSha":"a0df6e0e83b652c72bc78b0a1376c54d6ebc3bee","analyzedAt":"2026-09-06T10:13:38.901Z","contentChangedAt":"2026-09-06T10:13:38.901Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}