Closed
Description
Describe the problem
Arduino sketches may contain files under subfolders:
🐛 After a "Save As..." operation, any subfolders are lost and the files are all moved to the root sketch folder.
To reproduce
- Click the following link to download the demonstration sketch:
HasSubfolders.zip - Unzip the downloaded file.
- Take note of the file structure of the sketch:
HasSubfolders/ ├── HasSubfolders.ino └── src/ └── FromSubfolder.h
- Select File > Open from the Arduino IDE menus.
- Select the
HasSubfolders.ino
file from the unzipped folder. - Select File > Save As..." from the Arduino IDE menus.
- Save the sketch to any convenient name and location.
- Select Sketch > Show Sketch Folder from the Arduino IDE menus.
🐛 The subfolder structure of the sketch was lost:
HasSubfoldersAfterSaveAs/
├── FromSubfolder.h
└── HasSubfoldersAfterSaveAs.ino
Expected behavior
A "Save As" operation does not make any changes to the sketch file structure.
Arduino IDE version
Operating system
- Windows
- Linux
- macOS
Operating system version
- Windows 11
- Ubuntu 22.04
- macOS Ventura
Additional context
I bisected the regression to 0ab2826 (the fault does not occur when using 2aad0e3).
Additional reports
- Subfolder structure of sketch lost after "Save As" operation #2077 (comment)
- https://forum.arduino.cc/t/ide-2-2-1-save-as-does-not-copy-subfolders-correctly/1191437
Issue checklist
- I searched for previous reports in the issue trackerI verified the problem still occurs when using the latest nightly buildMy report contains all necessary details
Activity
per1234 commentedon May 29, 2023
Hi @jsmwrench. Thanks for your report.
Please check to see whether the unexpected 36 files are also present in the folder on that external drive.
A common misconception is that an Arduino sketch is a file. The sketch is actually a folder. When you do a "Save As" operation with a sketch, all the files from the original sketch folder are saved to the folder that is the target of the "Save As" operation. So if you had previously placed all those 36 files in the original sketch folder then it is expected that they would also be present in the new folder as well.
fwlrichard commentedon May 29, 2023
Save as is also dumping All Files from all sub folders into the Sketch folder.
Original Sketch Folder Containing only the Sketch and a data folder. Data folder contains 4xfile.txt files.
Open Sketch click "Save As" and as you can see now the new Sketch folder contains the sketch and all 4 of the data files from the "data" folder that is now gone.
@per1234 - All previous versions of the Arduino IDE have been able to maintain file structure when doing a "Save As. "
Problem started with IDE Version: 2.1.0
Date: 2023-04-19T15:31:10.185Z
CLI Version: 0.32.2
jsmwrench commentedon May 30, 2023
None of the new files are in the original folder. The original folder only had the sketch itself and the AccelStepper library in it. I opened the sketch in VS Code and saved as a new file on my computer and when I did, the IDE created all of these files in the same folder as the newly saved sketch.

Folder I took it from:
New Folder:

jsmwrench commentedon May 30, 2023
Okay, so I just figured out that all of the extra files are from the AccelStepper library. I'm not sure why it took all of those files on "Save As", but it did. I guess this can be closed.
fwlrichard commentedon May 31, 2023
per1234
Please do not close this jsmwrench attachment shows the exact same issue that I have. It is not a "misconception" of the sketch being a folder. You can clearly see that the file folder "AccelStepper" is now missing in the second picture jsmwrench posted. I would put money on the fact that all of the extra files were originally contained within the "AccelStepper" Folder.
This is not normal or expected behavior of "SaveAs"
"SaveAs" is dumpling all sub folder files into the root sketch folder.
Expected result is for the original file folder structure to remain intact, just as it would if you clicked "Save."
[-]when saving as, sketch folder fills with files (libraries???)[/-][+]Subfolder structure of sketch lost after "Save As" operation[/+]per1234 commentedon Jul 13, 2023
I am able to reproduce the fault and have updated the report to clearly describe the bug. Thanks for bringing this to our attention @jsmwrench and for your clarification @fwlrichard
fix: sketch Save As preserves the folder structure