My site has a few hundred files that have been uploaded into the files directory. I'd like to do some weeding of that /files directory.

For any particular file in the files directory, how can I find out if that file is being used on a particular page in Drupal, either as a "file attachment" or referenced by a download link in the text or an embedded image link?

Is there some magical module that will help with this? Thanks all!

Comments

steve02476’s picture

I was able to come up with an SQL snippet that will show me what nodes have ever mentioned a particular file:

SELECT DISTINCT `nid` 
FROM  `node_revisions` 
WHERE  `body` LIKE  '%filename_being_searched_for.jpg%' 

But I think this shows me node ids where a past revision had a particular file linked within it. And it doesn't show me if a file in the files directory is attached to a particular node.

Any ideas?

steve02476’s picture

I just found the Search & Replace Scanner module http://drupal.org/project/scanner - it knows how to search for html strings AND it is happy to return only published nodes (not prior revisions).

WorldFallz’s picture

You should be able to use views for this. There's a couple of different ways depending what module you use for file attachments. for example, if you use the core upload module you can make a node view and use the 'upload: has attached files' filter.

steve02476’s picture

I don't know how to use Views yet, although I have it installed. I guess this is a good learning opportunity for me! Thanks for the tip.