{"record":{"id":"2b8c596475ddaaab","repo":"arduino/Arduino","slug":"failed-to-rename-sketch-folder","errorCode":null,"errorMessage":"Failed to rename sketch folder","messagePattern":"Failed to rename sketch folder","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"arduino-core/src/processing/app/Sketch.java","lineNumber":298,"sourceCode":"   * moves the sketch directory, not leaving anything in the old place.\n   * This operation does not *save* the sketch, so the files on disk are\n   * moved, but not modified.\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 renameTo(File newFolder) throws IOException {\n    // Check intended rename (throws if there is a problem)\n    File newPrimary = checkNewFoldername(newFolder);\n\n    // Rename the sketch folder\n    if (!getFolder().renameTo(newFolder))\n      throw new IOException(tr(\"Failed to rename sketch folder\"));\n\n    folder = newFolder;\n\n    // Tell each file about its new name\n    for (SketchFile file : files)\n      file.renamedTo(new File(newFolder, file.getFileName()));\n\n    // And finally, rename the primary file\n    getPrimaryFile().renameTo(newPrimary.getName());\n  }\n\n\n  public SketchFile addFile(String newName) throws IOException {\n    // Check the name will not cause any conflicts\n    File newFile = new File(folder, newName);\n    checkNewFilename(newFile);\n\n    // Add a new sketchFile","sourceCodeStart":280,"sourceCodeEnd":316,"githubUrl":"https://github.com/arduino/Arduino/blob/a0df6e0e83b652c72bc78b0a1376c54d6ebc3bee/arduino-core/src/processing/app/Sketch.java#L280-L316","documentation":"renameTo first validates the target via checkNewFoldername, then performs the actual filesystem rename of the sketch folder. It throws IOException when File.renameTo returns false, i.e. the OS-level rename failed after validation passed.","triggerScenarios":"Sketch.renameTo(newFolder) where the OS cannot move the folder: target on a different filesystem/mount, folder locked by an open file handle, or insufficient write permission on the parent directory.","commonSituations":"Sketch open in another program (editor, file manager) holding handles; renaming across drives; read-only network share or synced folder; on Windows a file inside is open and locked.","solutions":["Close any programs that have files in the sketch folder open","Rename to a path on the same filesystem/volume","Check write permission on the sketch's parent directory","Retry after unlocking files; on Windows close Explorer windows inside the folder","As a fallback, copy the folder manually and delete the original"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if (!getFolder().getParentFile().canWrite()) throw new IllegalStateException(\"Parent dir not writable\");\nif (!newFolder.getParentFile().equals(getFolder().getParentFile())) throw new IllegalStateException(\"Cross-volume rename\");","typeGuard":null,"tryCatchPattern":"try {\n  sketch.renameTo(newFolder);\n} catch (IOException e) {\n  // fallback: copy + delete\n  FileUtils.copyDirectory(sketch.getFolder(), newFolder);\n  FileUtils.deleteDirectory(sketch.getFolder());\n}","preventionTips":["Keep rename targets on the same filesystem/volume","Close editors and file managers holding sketch files open","Check write permission on the parent directory first","Prefer copy+delete fallback on network/synced folders"],"tags":["filesystem","rename","io"],"backgroundTag":"file-write-failed","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"}