Directory Truncator


Recently I needed some code to truncate a directory of files or folders, for example I wanted to remove files or directories given a max number of files or directories. Polyhedral 'foam' by truncated octahedraThis is a common task when you have backups and you don’t want every single backup since forever, but you want to keep the last 5 ones. Another common scenario is when you have builds and you only probably want the last 10 (particularly if your build is used only by 4 people that seat across from you).

Anyhow, I have written similar code in the past and I know I will probably need something that does the same thing in the future, so I created a super small library and I put it on github.

I think the tests explain better what the code does than I do. So have a look.

There are a few things that I want to add to this project

  1. Logging and or console output so you know what happened, I couldnt so far decide on what is the best approach or if I want to choose one, so I ll do that tomorrow .
  2. On error, proceed to the next file/folder.
  3. Have a StartsWith parameter(on both methods), so that it only deletes files or directory that start with
  4. Turn it into a service

There are probably more things that could be done with it, but honestly, that is all I need.

Comments, questions or any feedback welcome!

Note: The image above is totally unrelated but I found it looking for truncated. What I found interesting about it is that the article this image relates to is about the Wearie-Phelan structure, this structure inspired the Beijing National Aquatics Centre and other cool stuff you can read here.

Happy holidays


3 Responses to “Directory Truncator”

  1. Nice util! A chocolatey install for this would kill.

  2. 2 roundcrisis

    Had a quick look, nice. I need to figure how to make a chocolatey install 🙂

  1. 1 DirectoryTruncator–Update II « roundcrisis.Find<Solution>()

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: