The simplest 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 on the file tab at the top of the editor window, and select "Delete" from the menu. The file disappears when ready — Arduino does not move it to a trash folder first, so the deletion is permanent.
If you are working with a sketch that has multiple tabs (which is how Arduino organizes separate files within one project), each tab represents a different file. The main file always stays — you cannot delete the .ino file that holds your sketch's core code — but any secondary files you created can be removed this way.
Before you delete, make sure no other part of your sketch still calls functions or variables from that file. If your main code references something that lived in the deleted file, your sketch will not compile and you will see an error message naming the missing function or variable.
Key Takeaways
- Right-click the file tab and select Delete to remove any secondary file from your sketch when ready and permanently.
- The main .ino file cannot be deleted — you can only remove extra files you added yourself.
- Check your code for any references to functions or variables in the file before you delete it, or your sketch will fail to compile.
- If you delete a file by mistake, close the sketch without saving and reopen it to recover the lost file.
Understanding Arduino file structure and tabs
An Arduino sketch is a folder on your computer that contains at least one .ino file (the main code file) and may contain additional files with different extensions. Each file shows up as a tab at the top of the editor. The main tab is always named after your sketch — if your sketch is called "MotorControl", the main file is MotorControl.ino and its tab cannot be closed or deleted.
Secondary files typically have extensions like .h (header files), .cpp (C++ source files), or .c (C source files). You create these when your sketch grows large enough that you want to organize code into separate pieces, or when you are using a library that requires multiple files. Each one appears as its own tab, and each one can be removed independently.
When you delete a file, Arduino removes it from the sketch folder on your computer. The IDE does not keep a backup or move it to a recycle bin — the file is gone. This is why it is important to check your code first and make sure nothing else depends on what that file contains.
What happens if your code still references the deleted file
If you delete a file that contains a function your main code calls, or a variable your main code uses, the Arduino IDE will show a compilation error when you try to upload the sketch. The error message will name the missing function or variable and tell you it is undefined or undeclared.
To fix this, you have two choices: restore the file (by closing without saving and reopening the sketch) or remove the references to it from your main code. If you are keeping the file, search your sketch for any calls to functions that lived in the deleted file and remove those lines. If you are removing the file, make sure you have already moved any code you want to keep into your main .ino file or another file you are keeping.
How to recover a file you deleted by mistake
If you delete a file and when ready realize you made a mistake, close the sketch without saving. Use File > Close (or close the IDE window entirely) and do not click Save when prompted. When you reopen the sketch, the deleted file will be back because Arduino only writes changes to disk when you save.
This recovery only works if you have not saved the sketch since the deletion. Once you save, the file is permanently gone from the sketch folder. If you have already saved, check your computer's recycle bin or trash folder — the file may still be there and you can restore it to the sketch folder manually.
Organizing your sketch with multiple files
As your Arduino project grows, splitting code into multiple files makes it easier to read and maintain. A common pattern is to put all the setup and configuration code in the main .ino file, put helper functions in a separate .cpp file, and put variable declarations and function prototypes in a .h header file.
To add a new file, click the down arrow next to the sketch name at the top of the editor and select "New Tab". Give the file a name and choose its type — Arduino will add the correct file extension automatically. Once you have created the file, you can write code in it just like the main file, and your main code can call any functions defined in the new file.
When you are done with a file and no longer need it, removing it keeps your sketch folder clean and makes it easier for someone else (or you, months later) to understand what the sketch actually does. Delete files you are not using rather than leaving them in place.
Differences between deleting and just leaving a file unused
You might be tempted to leave an old file in your sketch folder but straightforward not use it, thinking you might need it later. This creates confusion — anyone reading your sketch will wonder what that file does and whether it matters. It also makes your sketch folder harder to navigate when you have many files.
If you think you might need the code later, copy the file to a separate folder on your computer before you delete it from the sketch. That way your active sketch stays clean, but you still have a backup of the code. Many developers keep a "code snippets" or "archive" folder for this purpose.
Frequently Asked Questions
Can I delete the main .ino file?
No. The main .ino file — the one named after your sketch — cannot be deleted from within the Arduino IDE. You can only delete secondary files you created. If you want to remove the entire sketch, you must delete the sketch folder itself from your computer using your file manager.
What if I delete a file and then try to upload my sketch?
If the deleted file contained code your sketch needs, the upload will fail with a compilation error naming the missing function or variable. You will need to either restore the file or remove the references to it from your code before you can upload successfully.
Does deleting a file from Arduino also delete it from my computer?
Yes. When you delete a file from the Arduino IDE, it removes the file from the sketch folder on your hard drive. The file does not go to your recycle bin — it is deleted directly. If you need it back, close without saving to recover it, or restore it from a backup.
Can I rename a file instead of deleting it?
The Arduino IDE does not have a built-in rename function for files. To rename a file, close the sketch, use your computer's file manager to rename the file in the sketch folder, then reopen the sketch in Arduino. The tab will show the new name automatically.