Skip to content

Subfolder structure of sketch lost after "Save As" operation #2077

Closed
@jsmwrench

Description

@jsmwrench

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

  1. Click the following link to download the demonstration sketch:
    HasSubfolders.zip
  2. Unzip the downloaded file.
  3. Take note of the file structure of the sketch:
    HasSubfolders/
    ├── HasSubfolders.ino
    └── src/
        └── FromSubfolder.h
    
  4. Select File > Open from the Arduino IDE menus.
  5. Select the HasSubfolders.ino file from the unzipped folder.
  6. Select File > Save As..." from the Arduino IDE menus.
  7. Save the sketch to any convenient name and location.
  8. 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

94d2962

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

Issue checklist

  • I searched for previous reports in the issue tracker
    I verified the problem still occurs when using the latest nightly build
    My report contains all necessary details

Activity

self-assigned this
on May 29, 2023
per1234

per1234 commented on May 29, 2023

@per1234
Contributor

Hi @jsmwrench. Thanks for your report.

the original file was opened from an external drive. I then used File/Save As to save it to my "sketches" folder.

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

fwlrichard commented on May 29, 2023

@fwlrichard

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.

SaveAs_Issue_ORG

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.

SaveAs_Issue_BAD

@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

jsmwrench commented on May 30, 2023

@jsmwrench
Author

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:
From folder

New Folder:
New Folder

jsmwrench

jsmwrench commented on May 30, 2023

@jsmwrench
Author

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

fwlrichard commented on May 31, 2023

@fwlrichard

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."

changed the title [-]when saving as, sketch folder fills with files (libraries???)[/-] [+]Subfolder structure of sketch lost after "Save As" operation[/+] on Jul 13, 2023
per1234

per1234 commented on Jul 13, 2023

@per1234
Contributor

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

removed their assignment
on Jul 13, 2023
self-assigned this
on Nov 23, 2023
added a commit that references this issue on Jan 15, 2024
074f654
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @kittaakos@per1234@jsmwrench@fwlrichard

    Issue actions

      Subfolder structure of sketch lost after "Save As" operation · Issue #2077 · arduino/arduino-ide