Skip to content

Instantly share code, notes, and snippets.

@maxfridbe
Created May 14, 2020 16:36
Show Gist options
  • Save maxfridbe/de1a28806a55b443f6692b796fd09b50 to your computer and use it in GitHub Desktop.
Save maxfridbe/de1a28806a55b443f6692b796fd09b50 to your computer and use it in GitHub Desktop.
..fucking powershell
$id = get-random
$maxSizeMB = 500
$code = @"
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
namespace HelloWorld
{
public class Program$id
{
public static List<string> ListDirsToDel()
{
var todel = new List<string>();
var dirs = Directory.EnumerateDirectories(".");
foreach (var d in dirs){
var size = DirSize(new DirectoryInfo(d));
var sizemb = size/1024f/1024f;
Console.WriteLine( "Size: "+sizemb + "mb \t\tDir "+d);
if($maxSizeMB > sizemb)
{
todel.Add(d);
}
}
return todel;
}
public static long DirSize(DirectoryInfo dir)
{
return dir.GetFiles().Sum(fi => fi.Length) +
dir.GetDirectories().Sum(di => DirSize(di));
}
}
}
"@
Add-Type -TypeDefinition $code -Language CSharp
$data = iex "[HelloWorld.Program$id]::ListDirsToDel()"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment