Click here to Skip to main content
Click here to Skip to main content

Find Unused Files: v1.3

, 16 Mar 2013
Rate this:
Please Sign up or sign in to vote.
Finds unused files and images in your website projects.

Introduction

The other day at work I was cleaning up a project and got frustrated because i wanted to remove all images that are no longer referenced inside CSHTML, CSS, and LESS files ..but couldn't find any soft or plugin that would help me, so I got stuck with selecting each image name one by one and then searching through the entire project for each file to see if I got a match or not ..Grrrrr!

So I decided to whip up a little soft to help automate just that.  

Works as a Standalone Application, from the Windows Explorer context menu, from the Command Line, or as a Visual Studio extension. Thank's to the command line it can easily be integrated with your favorite development IDE too. 

 

Main Dialog

 Thumbnail Preview

 

Parsing Dialog

 

 Windows Explorer (context menu)  

 

 

Visual Studio (context menu)

 

The process was really easy, so unless i missed something, i'm surprised i couldn't find some program on the web that already did just that.

Anyways here's how it works: 

  1. enter a regexp that matches files you want to match
  2. choose if you want to match if they are used or not used
  3. choose what filetypes you want to search within to see if they have references in there
  4. select your starting directory 
  5. ......processing 

The simple logic behind it:

  1. load all file names from base directory & sub-directories
  2. extract all file names that match what we are looking for
  3. extract all file names that match which files we will be searching in
  4. iterate over each of the files we are searching in
  5. open each file and iterate over the content
  6. check if the content contains a match and add to a match list if so
  7. do a diff between matched and all

That's all, and it's pretty fast too. And since it uses standard regexp as input, you can match pretty much anything in any type of file. 

Features: 

  • Can be launched via the command line. Like this it's easy to integrate with Visual Studio, Eclipse, Zend Studio, NetBeans, IntelliJ IDEA, etc.  
  • Double clicking a path in the visible list will open the directory the file is contained in
  • Once file processing is done you can toggle the visible list between used/unused lists
  • Select items in list and export the paths to a text file for later investigation 
  • Regexp criteria is saved after successful search and restored on application launch
  • Selecting one or more paths in the visible list and clicking delete, will prompt you if you really want to delete the file(s)
  •   

Requires .NET 4 for the Application or .NET 4.5 / Visual Studio 2012 for the Plug-in

 

Change log  

v1.3

  • Alt-Click in list will show image thumbnail if it's an image
  • Double-Click on list will open & set focus to item in solution explorer (VSIX only)
  • Shell integration (EXE only)
    • Add/Remove from Help menu, or register/unregister from command line with -s t
  • More file stats

v1.2

  • Changed UI a bit
  • Context menus
    • Select All
    • Select Other
    • Export Selection
    • Delete Selection
    • Explore Here
    • Verify Selection (VSIX only: launches automated VS file search)
      • In Project
      • In Solution
  • Command line parameters (EXE only)
    • -p path
    • -r report type
    • -f find regexp
    • -i inside regexp
  • Help Menu
    • Manual
    • Change-log
    • Website
    • About
    • License
  • More file stats
  • More error handling  

v1.1

  • Disable delete button if no are files selected
  • Enabled searching in website projects (VSIX)
  • More error messages on invalid and/or unsuccessful operations

v1.0 (Visual Studio Plug-in)

  • .EXE and VSIX versions now share same code-base
  • Various modifications to accommodate different behavior in Visual Studio Mode & Standalone Mode
  • Enabled searching in application projects

v1.0 (Application)

  • Toggle between used/unused lists
  • Export used/unused lists
  • Delete file(s) with confirmation prompt
  • Save search criteria after search
  • Show errors on invalid regexps
  • Restore search criteria on application launch
  • Double click used/unused list opens containing directory
  • Allow passing file/directory path via command line 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Robert Hoffmann
Software Developer (Senior) Index Multimedia
France France
Internet & Technology related professional since 1994. Passionate about WEB 2.0 and Community/Social networking related type Websites, or anything that is tech related to bridging the gap between the User and his everyday Multimedia Experience.
Follow on   Twitter   Google+   LinkedIn

Comments and Discussions

 
QuestionDoesn't Work PinmemberMember 103113942-Oct-13 6:25 
AnswerRe: Doesn't Work PinmemberRobert Hoffmann2-Oct-13 10:46 
GeneralMy vote of 5 Pinmemberpeterboulton18-Mar-13 2:58 
GeneralRe: My vote of 5 [modified] PinmemberRobert Hoffmann18-Mar-13 6:15 
GeneralRe: My vote of 5 Pinmemberpeterboulton18-Mar-13 6:29 
GeneralRe: My vote of 5 PinmemberRobert Hoffmann18-Mar-13 6:46 
GeneralRe: My vote of 5 Pinmemberpeterboulton18-Mar-13 7:34 
GeneralMy vote of 5 PinmemberNeoPunk3-Mar-13 22:22 
Very nice!

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140821.2 | Last Updated 16 Mar 2013
Article Copyright 2013 by Robert Hoffmann
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid