First you can use the File > Reduce Project command by selecting the final composition so that the files that were imported by not used in the project gets removed from the project, after that use the command File>Collect files and make sure that all files option is choosen before you click the Collect file button.
There is a very good video step by step tutorial at https://bluefx.net/after-effects-templates/collect-missing-files-tutorial/ which can refer to in case there is any confusion.