<p>We are migrating our works repository so I want to do a cull of all the unreferenced files that exist in the source tree before moving it into the nice fresh (empty) repository.</p>

<p>So far I have gone through by hand and found all the unreferenced files that I know about but I want to find out if I have caught them all. One way would be to manually move the project file by file to a new folder and see what sticks when compiling. That will take all week, so I need an automated tool.</p>

<p>What do people suggest?</p>

<p>Clarifications:<br>
1) It is C++.<br>
2) The files are mixed. I am looking for files that have been superseded by others but have left to rot in the repository - for instance file_iter.h is not referenced by any other file in the program but remains in the repository just in case someone wants to compile a version from 1996! Now we are moving to a fresh repository we can safely junk all the files that are no longer used.<br>
3) Lint only finds unused includes - not unused files (I have the 7.5 manual in front of me).</p>

[{'answer_id': 51557, 'author': 'Andrew', 'author_id': 826, 'author_profile': 'https://Stackoverflow.com/users/826', 'pm_score': 2, 'selected': False, 'text': "<p>You've tagged this post with <strong>c++</strong>, so I'm assuming that's the language in question. If that's the only thing that's in the repository then it shouldn't be too hard to grep all files in the repository for each filename to give you a good starting point. If the repository contains other files (metadata, support files, resources, etc) then you're probably going to need to do it manually.</p>\n"}, {'answer_id': 51568, 'author': 'Maximilian', 'author_id': 1733, 'author_profile': 'https://Stackoverflow.com/users/1733', 'pm_score': 0, 'selected': False, 'text': '<p>A static source code analysis tool like lint might do the job. They will tell you if a piece of code will never be called.</p>\n'}, {'answer_id': 51626, 'author': 'Maximilian', 'author_id': 1733, 'author_profile': 'https://Stackoverflow.com/users/1733', 'pm_score': 0, 'selected': False, 'text': '<p>Have you taken a look at <a href="http://sourcenav.sourceforge.net/" rel="nofollow noreferrer">Source-Navigator</a>? It can be used as an IDE but I found to be very good at analyzing source code structure. For example, it can find out where and if a certain method is used in your source code.</p>\n\n<p>I don\'t know if it\'s scriptable but it might be a good starting point for you.</p>\n'}, {'answer_id': 52943, 'author': 'mweerden', 'author_id': 4285, 'author_profile': 'https://Stackoverflow.com/users/4285', 'pm_score': 1, 'selected': False, 'text': "<p>I can't offer an existing tool for it, but I would expect that you can get a lot of this information from you build tools (with some effort, probably). Typically you can at least let the build tool print the commands it would run, without actually running them. (E.g. the <code>-n</code> option of <code>make</code> and <code>bjam</code> does this.) From it you should be able to extract at least the used source files.</p>\n\n<p>With the <code>-MM</code> of <code>g++</code> you can get all the non-system header files for the given source files. The output is in the form of a <code>make</code> rule, but with some filtering this shouldn't be a problem.</p>\n\n<p>I don't know if this helps; it's just what I would try in your situation.</p>\n"}, {'answer_id': 526601, 'author': 'Anna-Jayne Metcalfe', 'author_id': 28201, 'author_profile': 'https://Stackoverflow.com/users/28201', 'pm_score': 1, 'selected': False, 'text': '<p>You can actually do this indirectly with Lint by running a "whole project analysis" (in which all files are analysed together rather than individually).</p>\n\n<p>Configure it to ignore everything but unreferenced variable/enum/function etc warnings and it should give you a reasonable indicator of where the deadwood lies without those issues being obscured by any others in the codebase.</p>\n'}]
['https://Stackoverflow.com/questions/51548', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/342/']