The fastest way to remove a file from your Arduino sketch
To remove a file from your Arduino sketch, open the sketch in the Arduino IDE, right-click the file tab at the top of the editor, and select Delete. The file disappears immediately. If you want to keep a copy before deleting, save it elsewhere first — the IDE does not send deleted files to trash, so recovery is not possible once you confirm the deletion.
The process differs slightly depending on whether you are removing a header file (.h), a C++ file (.cpp), or a secondary sketch file (.ino). All three use the same right-click method, but understanding what each file does helps you avoid accidentally removing something your sketch needs to compile.
Key Takeaways
- Right-click any file tab in the Arduino IDE and select Delete to remove it permanently from your sketch.
- Deleted files do not go to a trash folder, so back up any file you might need later before removing it.
- Removing a .h or .cpp file that your sketch still references will cause a compilation error, which tells you exactly what is missing.
- Multi-file sketches store all files in a single folder, so deleting a file from the IDE removes it from that folder on your computer.
Understanding file types in an Arduino sketch
An Arduino sketch can contain multiple files, each serving a different purpose. The main file always ends in .ino and holds your setup() and loop() functions. Header files (.h) contain function declarations and class definitions. Implementation files (.cpp) contain the actual code for those functions and classes. Secondary .ino files let you organize code into logical sections without creating separate libraries.
When you create a new tab in the Arduino IDE, you choose what type of file to add. The IDE stores all files in the same folder on your computer, so deleting a file through the IDE removes it from disk permanently. This is why backing up matters — there is no undo and no recovery option.
Step-by-step removal process
Open your sketch in the Arduino IDE. At the top of the editor window, you will see file tabs — one for each file in your sketch. The main .ino file is always there; any additional files appear as separate tabs to its right.
Right-click the tab of the file you want to remove. A small menu appears with options including Delete. Click Delete. The IDE asks you to confirm — click Yes or OK depending on your IDE version. The file tab vanishes, and the file is removed from your sketch folder on disk.
If you accidentally delete the wrong file, close the sketch without saving and reopen it. The file will still be there. Once you close the IDE or open a different sketch, the deletion becomes permanent.
What happens when you remove a file your sketch needs
If you delete a header or implementation file that your code still references, the sketch will not compile. The error message tells you exactly what is missing — for example, "fatal error: MyLibrary.h: No such file or directory". This error is actually helpful because it shows you immediately that something is broken.
To fix it, you have two options: restore the file by undoing the deletion (if you have not closed the IDE yet), or remove the references to that file from your remaining code. Search your sketch for the file name or any functions it contained, then delete or comment out those lines. After that, the sketch should compile again.
Removing secondary .ino files
Secondary .ino files are useful for organizing large sketches into logical sections. Each file can contain functions, variables, and setup code. When you remove a secondary .ino file, any functions defined in it become unavailable to the rest of your sketch.
Before deleting a secondary .ino file, search your main sketch file for any function calls that come from it. If your main code calls a function defined in the file you are about to delete, you will get a compilation error. Either move those functions to your main .ino file first, or keep the secondary file. The right-click delete method works the same way — just confirm the deletion when prompted.
Backing up files before deletion
The safest approach is to save a copy of any file before removing it. Open the file tab, select all the code (Ctrl+A on Windows or Linux, Cmd+A on Mac), copy it, and paste it into a text editor. Save that file somewhere outside your sketch folder with a name like "MyFile_backup.txt". Now you can delete the file from your sketch knowing you have a copy if you need it later.
Alternatively, you can rename a file instead of deleting it. Right-click the tab and select Rename, then add "_old" or "_unused" to the end of the name. This keeps the file in your sketch folder but makes it clear it is not in use. You can delete it later once you are confident your sketch works without it.
Frequently Asked Questions
Can I undo a file deletion in the Arduino IDE?
Only if you have not closed the IDE or opened a different sketch. Close your current sketch without saving, then reopen it — the deleted file will still be there. Once you close the IDE or switch sketches, the deletion is permanent and cannot be undone.
What happens to the file on my computer when I delete it from the IDE?
It is removed from your sketch folder on disk. The Arduino IDE does not move deleted files to your system trash — they are gone immediately. This is why backing up is important if there is any chance you might need the file later.
Can I delete the main .ino file?
No. The Arduino IDE will not let you delete the main sketch file — the one with your setup() and loop() functions. You can delete all other files, but the main .ino file must remain for the sketch to exist.
How do I know if a file is safe to delete?
Search your entire sketch for the file name and any function names it contains. If nothing references it, the file is safe to remove. You can also try deleting it and attempting to compile — if the sketch compiles without errors, the file was not needed.
Can I remove a file and then add it back later?
You can create a new file with the same name, but the original file is gone. If you had code in it, you will need to rewrite that code or restore it from a backup. This is why saving a copy before deletion is a good habit.