arduino/Arduino · error · IOException

Sorry, the folder "{0}" already exists.

Error message

Sorry, the folder "{0}" already exists.

What it means

checkNewFoldername validates the target folder for a rename/saveAs and throws IOException if the destination folder already exists on disk. This prevents overwriting or merging into an existing sketch directory.

Source

Thrown at arduino-core/src/processing/app/Sketch.java:247

        return i;
      i++;
    }
    return -1;
  }

  /**
   * Check if renaming/saving this sketch to the given folder would
   * cause a problem because: 1. The new folder already exists 2.
   * Renaming the primary file would cause a conflict with an existing
   * file. If so, an IOEXception is thrown. If not, the name of the new
   * primary file is returned.
   */
  protected File checkNewFoldername(File newFolder) throws IOException {
    String newPrimary = FileUtils.addExtension(newFolder.getName(), DEFAULT_SKETCH_EXTENSION);
    // Verify the new folder does not exist yet
    if (newFolder.exists()) {
      String msg = I18n.format(tr("Sorry, the folder \"{0}\" already exists."), newFolder.getAbsoluteFile());
      throw new IOException(msg);
    }

    // If the folder is actually renamed (as opposed to moved somewhere
    // else), check for conflicts using the new filename, but the
    // existing folder name.
    if (!newFolder.getName().equals(folder.getName()))
      checkNewFilename(new File(folder, newPrimary));

    return new File(newFolder, newPrimary);
  }

  /**
   * Check if renaming or adding a file would cause a problem because
   * the file already exists in this sketch. If so, an IOEXception is
   * thrown.
   *
   * @param newFile
   *          The filename of the new file, or the new name for an

View on GitHub (pinned to a0df6e0e83)

Solutions

  1. Choose a different folder name that does not exist yet
  2. Delete or move the existing folder if it is no longer needed
  3. Check File.exists() before calling renameTo/saveAs
  4. If case-insensitivity is the issue, pick a name unique ignoring case

Example fix

// before
sketch.saveAs(new File(sketchesDir, "Blink")); // fails if Blink exists
// after
File target = new File(sketchesDir, "Blink");
if (target.exists()) target = new File(sketchesDir, "Blink2");
sketch.saveAs(target);
Defensive patterns

Strategy: validation

Validate before calling

if (target.exists()) {
  throw new IllegalArgumentException("Target folder exists: " + target);
}

Type guard

static boolean isFreeFolderName(File parent, String name) {
  return !new File(parent, name).exists();
}

Try / catch

try {
  sketch.renameTo(newFolder);
} catch (IOException e) {
  System.err.println("Name collision: " + e.getMessage());
  // prompt user for a different name
}

Prevention

When it happens

Trigger: Sketch.renameTo() or Sketch.saveAs() called with a File path for a folder that already exists on the filesystem.

Common situations: Renaming a sketch to a name that collides with an existing sketch in the same directory; saveAs to a folder created earlier by a failed save; case-insensitive filesystems colliding on names differing only by case (Windows/macOS).

Understand the failure class

Background: "already exists" / EEXIST / FileAlreadyExistsException: what the 'file already exists' error means and how to fix it — this error's family across 37 libraries.

Related errors


AI-assisted analysis of arduino/Arduino@a0df6e0e83 (2026-09-06). Data as JSON: /api/errors/ceac8a3deb725725. Report an issue: GitHub.