GithubHelp home page GithubHelp logo

adamfoneil / sourcefoldercleanup Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 2.0 93 KB

WinForms utility for freeing up disk space under source folder (bin, obj folders)

C# 100.00%
winforms disk-space code-cleaning

sourcefoldercleanup's Introduction

This is a small utility I'm working on to free up disk space on my Surface machine which has a relatively small 256GB drive. My main repo folder has large package/, bin/ and obj/ folders that accumulate a lot of stuff that doesn't need to be there all the time. There might something out there that already does this nicely, but as usual, this is just something I like working on.

img

This makes use of my WinForms.Library project to handle the form data binding with a ControlBinder<T> object, incidentally. I'm also using my JsonSettings.Library project to handle settings persistence in json. My Settings model is here.

private void frmMain_Load(object sender, System.EventArgs e)
{
	var monthValues = new int[] { 3, 6, 9, 12 }.Select(i => new ListItem<int>(i, i.ToString()));

	_settings = SettingsBase.Load<Settings>();
	_binder = new ControlBinder<Settings>();            

	_binder.Add(tbSourcePath, model => model.SourcePath);
	_binder.Add(chkDelete, model => model.Delete);
	_binder.Add(chkDeleteBinObj, model => model.DeleteBinAndObj);
	_binder.Add(chkDeletePackages, model => model.DeletePackages);
	
	_binder.AddItems(cbDeleteMonths,
		(model) => model.DeleteMonthsOld = cbDeleteMonths.GetValue<int>(),
		(model) => cbDeleteMonths.SetValue(model.DeleteMonthsOld), monthValues);

	_binder.Add(chkArchive, model => model.Archive);
	_binder.Add(tbArchivePath, model => model.ArchivePath);
	_binder.AddItems(cbArchiveMonths,
		(model) => model.ArchiveMonthsOld = cbArchiveMonths.GetValue<int>(),
		(model) => cbArchiveMonths.SetValue(model.ArchiveMonthsOld), monthValues);

	_binder.Document = _settings;
	chkArchive_CheckedChanged(null, new EventArgs());
	chkDelete_CheckedChanged(null, new EventArgs());
}

I'm also using WinForm.Library's EnumFiles method to find bin and obj directories. The base implementation looks like this:

public IEnumerable<string> GetSubfoldersNamed(string parentPath, string[] includeNames, string[] excludeNames = null)
{
	List<string> results = new List<string>();

	FileSystem.EnumFiles(parentPath, "*", directoryFound: (di) =>
	{
		if (includeNames.Any(name => di.Name.Equals(name)) && (excludeNames?.All(name => !di.FullName.Contains(name)) ?? true))
		{
			results.Add(di.FullName);
			return EnumFileResult.NextFolder;
		}

		return EnumFileResult.Continue;
	});

	return results;
}

sourcefoldercleanup's People

Contributors

adamfoneil avatar

Watchers

 avatar

sourcefoldercleanup's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.