Removal / delete of unused hierarchical sheets

Hi all,
I inherited a pretty complex KiCAD project with many hierarchical sheets. Some of them are use multiple time. Some other became obsolete after previous changes to the schematic, but are still present in the project directory (currently around 40-50 different sheet files).
Is there any way to clean up the project and find / move unused sheets to a separate directory?
Or find only used sheets and copy them to a new project folder?
Many thanks.

I assume you have a backup strategy in place with a project of this size / complexity. If you don’t, then that is the first thing to fix.

For the rest, KiCad does not delete unused files, it just ignores them, and it’s up to you to keep your project in a decent state. It looks like your predecessor did not do this. 50 files in a project is quite a lot. I’m guessing there are also a bunch of libraries in that project, maybe (old?) gerber files, saved error listings or exported netlists and other stuff… Deleting things is a bit error prone if you don’t know what those files are.

One simple thing you can do from the project manager is: File / Save As. This saves the whole project with a different name and location. I guess it takes all used schematics with it, but not any files that are not in use. I don’t know what this does with (used) libraries.

You can open: Schematic Editor / View / Hierarchy Navigator. It’s a quick way to browse through all the pages, and each page has it’s filename in the title block.

This seems to work:

paul@cezanne:~/projects/kicad/mumar_rack/resistor_programmable$ grep -in "Sheetfile" *sch
Resistor_Programmable.kicad_sch:1689:		(property "Sheetfile" "coils.kicad_sch"
Resistor_Programmable.kicad_sch:1727:		(property "Sheetfile" "resistors.kicad_sch"

I used grep to search for the string “Sheetfile” in all files ending with “sch”. (So that is in the schematic files. It lists the two subsheets used in the project I tried it on.

1 Like

I wondered if the “Archive all project files” also took everything or just what was current in the Project . . . not tested it but might be worth a try to see if it filters out the unused stuff.

No. “Archive Project” does not work because it uses the filename extensions. So it would backup all schematic files, regardless of whether they are in use or not.

1 Like

Thank you everyone.
Yes, we use remote git repo, so we have backup options if something goes wrong.
Will try grep for it.

EDIT: with grep , sed, ls and a few more single line command I managed to export unused files to a text file, then delete them. Many thanks!

1 Like