arduino/Arduino · error · IOException
No valid code files found
Error message
No valid code files found
What it means
listSketchFiles scans the sketch folder for valid source files (.ino/.pde/.c/.cpp/.h etc.) and throws IOException when it finds none. It guarantees a Sketch is never built from an empty or all-invalid directory.
Source
Thrown at arduino-core/src/processing/app/Sketch.java:117
* part of this sketch. Doesn't modify this SketchData instance, just
* returns a filtered and sorted list of File objects ready to be
* passed to the SketchFile constructor.
*
* @param showWarnings
* When true, any invalid filenames will show a warning.
*/
private List<SketchFile> listSketchFiles(boolean showWarnings) throws IOException {
Set<SketchFile> result = new TreeSet<>(CODE_DOCS_COMPARATOR);
for (File file : FileUtils.listFiles(folder, false, EXTENSIONS)) {
if (BaseNoGui.isSanitaryName(FileUtils.splitFilename(file).basename)) {
result.add(new SketchFile(this, file));
} else if (showWarnings) {
System.err.println(I18n.format(tr("File name {0} is invalid: ignored"), file.getName()));
}
}
if (result.size() == 0)
throw new IOException(tr("No valid code files found"));
return new ArrayList<>(result);
}
/**
* Create the data folder if it does not exist already. As a
* convenience, it also returns the data folder, since it's likely
* about to be used.
*/
public File prepareDataFolder() {
File dataFolder = getDataFolder();
if (!dataFolder.exists()) {
dataFolder.mkdirs();
}
return dataFolder;
}
public void save() throws IOException {View on GitHub (pinned to a0df6e0e83)
Solutions
- Put at least one valid .ino/.pde source file (with a valid file name) in the sketch folder
- Rename files to valid names (alphanumeric + underscore, starting with a letter)
- Open the correct folder — the one containing the code, not its parent
- Create a new sketch via File > New instead of opening the empty folder
Example fix
// before
new Sketch(new File("emptySketch"), main);
// after
File dir = new File("emptySketch");
File[] entries = dir.listFiles((d, n) -> n.endsWith(".ino"));
if (entries == null || entries.length == 0) {
System.err.println("Not a sketch folder: no .ino files");
return;
}
new Sketch(dir, main); Defensive patterns
Strategy: validation
Validate before calling
File[] sources = dir.listFiles((d, n) -> n.matches("[A-Za-z0-9_]+\\.(ino|pde|c|cpp|h)") );
if (sources == null || sources.length == 0) {
throw new IllegalArgumentException("No valid sketch sources in " + dir);
} Type guard
static boolean isValidSketchFolder(File dir) {
File[] f = dir.listFiles((d, n) -> n.toLowerCase().endsWith(".ino") || n.toLowerCase().endsWith(".pde"));
return dir.isDirectory() && f != null && f.length > 0;
} Try / catch
try {
sketch.load();
} catch (IOException e) {
if ("No valid code files found".equals(e.getMessage())) {
System.err.println(dir + " has no valid sketch files");
}
} Prevention
- Check the folder contains at least one .ino/.pde before opening
- Keep file names alphanumeric with underscores
- Don't strip source files when moving sketches between machines
- Enable showWarnings to see which files were skipped and why
When it happens
Trigger: Opening/saving a sketch whose folder contains zero files with a valid sketch extension — e.g. an empty folder, or a folder whose only files have invalid names that were skipped (with warnings when showWarnings is set).
Common situations: Pointing the IDE at an empty directory; a sketch moved from Windows where files got stripped; files with illegal characters in names silently ignored.
Understand the failure class
Background: EmptyResultError / "no results found": when an API or scraper succeeds but returns zero rows — this error's family across 9 libraries.
Related errors
- The sketch already contains a file named "{0}"
- no headers files (.h) found in {0}
- 'Missing '' + p + '' from library'
AI-assisted analysis of arduino/Arduino@a0df6e0e83 (2026-09-06).
Data as JSON: /api/errors/4430471ba7066011.
Report an issue: GitHub.