{"record":{"id":"60a09768f1d9bd64","repo":"arduino/Arduino","slug":"could-not-create-directory-0","errorCode":null,"errorMessage":"Could not create directory \"{0}\"","messagePattern":"Could not create directory \"(.+?)\"","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"arduino-core/src/processing/app/Sketch.java","lineNumber":343,"sourceCode":"   * Save this sketch under the new name given. Unlike renameTo(), this\n   * leaves the existing sketch in place.\n   *\n   * @param newFolder\n   *          The new folder name for this sketch. The new primary\n   *          file's name will be derived from this.\n   *\n   * @throws IOException\n   *           When a problem occurs. The error message should be\n   *           already translated.\n   */\n  public void saveAs(File newFolder) throws IOException {\n    // Check intented rename (throws if there is a problem)\n    File newPrimary = checkNewFoldername(newFolder);\n\n    // Create the folder\n    if (!newFolder.mkdirs()) {\n      String msg = I18n.format(tr(\"Could not create directory \\\"{0}\\\"\"), newFolder.getAbsolutePath());\n      throw new IOException(msg);\n    }\n\n    // Save the files to their new location\n    for (SketchFile file : files) {\n      if (file.isPrimary())\n        file.saveAs(newPrimary);\n      else\n        file.saveAs(new File(newFolder, file.getFileName()));\n    }\n\n\n    // Copy the data folder (this may take a while.. add progress bar?)\n    if (getDataFolder().exists()) {\n      File newDataFolder = new File(newFolder, \"data\");\n      // Check if data folder exits, if not try to create the data folder\n      if (!newDataFolder.exists() && !newDataFolder.mkdirs()) {\n        String msg = I18n.format(tr(\"Could not create directory \\\"{0}\\\"\"), newFolder.getAbsolutePath());\n        throw new IOException(msg);","sourceCodeStart":325,"sourceCodeEnd":361,"githubUrl":"https://github.com/arduino/Arduino/blob/a0df6e0e83b652c72bc78b0a1376c54d6ebc3bee/arduino-core/src/processing/app/Sketch.java#L325-L361","documentation":"saveAs validates the target folder, then creates it with mkdirs(); this error is thrown when mkdirs() returns false and the sketch directory could not be created. It means the save destination could not be materialized on disk.","triggerScenarios":"Sketch.saveAs(newFolder) where newFolder cannot be created: parent directory missing/unwritable, a file (not a directory) already exists at the path, or a path length/permission problem.","commonSituations":"Saving into a read-only location (Program Files, read-only USB stick); saving to a path whose parent doesn't exist or is a file; insufficient disk space or quotas; invalid characters in the path on Windows.","solutions":["Verify the parent directory exists and is writable before saving","Ensure no regular file occupies the target path","Pick a location with write access (Documents, home directory)","Check disk space and path length/character restrictions"],"exampleFix":"// before\nsketch.saveAs(new File(\"/readonly\", \"MySketch\"));\n// after\nFile target = new File(\"/readonly\", \"MySketch\");\nFile parent = target.getParentFile();\nif (parent != null && parent.canWrite() && !target.exists()) {\n  sketch.saveAs(target);\n} else {\n  System.err.println(\"Cannot create \" + target);\n}","handlingStrategy":"validation","validationCode":"File parent = target.getParentFile();\nif (parent == null || !parent.isDirectory() || !parent.canWrite() || target.exists()) {\n  throw new IllegalArgumentException(\"Cannot create \" + target);\n}","typeGuard":"static boolean canCreateDir(File target) {\n  File p = target.getParentFile();\n  return !target.exists() && p != null && p.isDirectory() && p.canWrite();\n}","tryCatchPattern":"try {\n  sketch.saveAs(newFolder);\n} catch (IOException e) {\n  System.err.println(\"Save failed, cannot create dir: \" + newFolder);\n}","preventionTips":["Save into user-writable locations (home, Documents)","Pre-create the parent directory structure yourself","Avoid paths with Windows-illegal characters or excessive length","Check disk space before large saves"],"tags":["filesystem","mkdir","io"],"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"}