Friday, May 06, 2011

File or Folder Delete Utility

I originally put this utility together for one very specific purpose: to delete all files in a given folder whose name started with a number (cleaning up after other processes). It has since been used for other purposes, so I made it easier to extend by using the "pipeline" pattern just like is commonly done with data filtering. File or folder names from the requested directory are passed through filters (Filters.cs). Those meeting filter requirements are processed (either logged or deleted).

The currently implemented filters are:
  • Date (always taken into account)
  • Starts with numeric
  • Name is a guid
It will target either files or folders. Launch the utility with no parameters to see instructions.

To extend with another filter:
  • Add methods to Filters.cs following same pattern as existing (returns IEnumerable of FileInfo for files; IEnumerable of string for folders).
  • Add parameter metadata for the new filter parameter in AppParams.cs.PARAM_STRINGS
  • Add a "mode" property for the new filter in AppParams.cs (Like existing NumericMode).
  • Add a method to read the new param from the command line and set the new property you created above (like existing SetNumericMode).
  • Update the help text that prints when no params or bad params are passed to the utility in Program.cs

Test before using, of course, but I hope it's of use to somebody. If you just want the utility, get it here; if you want the code, it's here.

No comments: