Recently, I have encountered a problem that my hard drive is becoming completely unpleasant, but, having gone through my personal files and deleting / moving all oversized video files, I still have a small amount of ROM. So I put my brain to the programmer’s work and decided that instead of carefully going through each folder and subfolder on my own and using the right-click function + Windows Properties to see how big the file is and whether it should be supported, I could write a simple code that will search for every file on my computer, throw it into the list by its full path and put its size next to it, and then sort it from the maximum to the minimum by file size. So I jumped online, started researching, and that’s when it all hit me a fan. I found a lot of code snippets that work for their assigned task, but whenever I try to use them, I encounter boats of build errors. However, the most promising thing I have found so far:
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 apply to any subdirectory. I was looking for how to grab files from subdirectories, but trying to integrate these code snippets with this problem turned out to be more problems than I could imagine. In a rare case when light was seen at the end of the tunnel, my program touched a directory that was apparently protected by the administrator privilege (I am the only user and, therefore, the administrator of my computer) and threw errors such as chimpanzees to the zoo throwing feces .
So, in general, I'm looking for help: -A program that looks for every file on my computer (I assume that starting from the "C: /" drive, I can access everything) -Selects each file, its size and path to this file and issues it to the list / array / independently -Sorts it by file size from maximum to smallest -Installs this list in a .txt file
In the last part, I do not need help, as I am well acquainted with the Streamwriter class. I can even get through sorting by file size using a quasi-simple parsing algorithm that I can do on the fly if my list / array / etc of files / paths / sizes all match the same patterns and can be converted to strings . Thus, approximately 90.23% of my problems are simply getting all the files, hitting or ignoring and saving password protected folders (I think that ignoring them would be better, since I very much doubt that anything in the protected folder should be ever deleted). Getting the paths and sizes of all these files and their organization.