Recently I've come into the problem that my hard drive is getting obnoxiously full, but after going through my personal files and deleting/moving all of the oversized video files, I still have a rather small amount of ROM available. So I put my programmer brain to work and decided that instead of meticulously going through each folder and subfolder myself and using the right-click + Properties function of Windows to see how big a file is and whether or not its worth keeping around, I could write a simple code that would search for every file on my computer, throw it into a list by its full path name, and put its file size right next to it, then sort it from greatest to least by file size. So I hopped online, started doing the research, and thats when everything hit the fan for me. I've found plentiful code snippets that work for their designated task but whenever I try to utilize them myself I run into boatloads of build errors. That said, the most promising thing that I've found so far is:
const string dir = "C:\\";
string[] fns = Directory.GetFiles(dir);
var Sort = from fn in fns
orderby new FileInfo(fn).Length descending
select fn;
foreach (string n in Sort)
Console.WriteLine(n);
Unfortunately this does not touch any subdirectory. I've looked up how to grab the files out of subdirectories, but trying to integrate those code snippets with this one proved more trouble than I could have imagined. On the rare occasion that light was seen at the end of the tunnel, my program would touch a directory that was apparently protected by Administrator privileged (I am the only user, and thus Administrator of my computer) and tossed out errors like a chimpanzee at a zoo tosses out feces.
So on the whole, what I am seeking assistance with is: -Program that searches every file on my computer (I am assuming that starting with the "C:/" drive is where I can access everything) -Takes each file, its size, and the path to that file and throws it onto a list/array/whatever -Sorts it by file size from greatest to least -Places this list into a .txt file
The last part I actually don't need help with since I am rather familiar with the Streamwriter class. I can even muck my way through sorting by file size with a quasi-simple parsing algorithm I can make on the fly if my list/array/etc of files/paths/sizes all conform to the same patterns and can be converted into strings. So roughly 90.23% of my issues are simply getting all the files, getting into or ignoring-and-continuing Admin protected folders (I think ignoring them would be best since I highly doubt anything in a protected folder should ever be deleted. Ever.) Getting the paths and sizes of all of those files, and organizing them.