Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I recently became responsible for a PHP / HTML / MySQL website.

The document structure is full of duplicate files and folders making the site appear more complex than it is.

Is there any tool I can use to process the files and find out which files are used and which are not so that I can purge all the redundant code from the file structure?

Also, can a tool identify if there are any missing files?

share|improve this question

3 Answers 3

If you want to see the files on a page-by-page basis, use a browser like Chrome that shows the files transferred. In Chrome, right-click on a page and select the "Inspect element" menu item. A new window pane will open in the lower half of the page with tabs named "Elements", "Resource", "Network", etc.

Click on the Network tab and then reload the page. All files transferred over the network will appear in the Name column. At the bottom of the pane are other tabs to group the files by type: Documents, Stylesheets, Images, etc.

If a file is missing, you will see a red 404 in the Status column.

share|improve this answer

There is no way to programmatically analyze the files you have to see which are used. One of the PHP scripts could do something as simple as <a href="<?= $filename ?>.html"> to reference an arbitrary file, and you'd have no way of detecting that that target file was in use.

However, an alternative is to poll the website access logs. If you have logs going back for a sufficient time, you could simply parse out the name of every file that has been served, and assume that any files that have never been served aren't used. I'd recommend moving the "unused" files to a safe place just in case you need to bring one of them back.

share|improve this answer

Another possibility is to import all the code into a IDE, and use the refactoring functions; if you try to delete a file they can track if it is included somewere and warn you before deleting it

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.