static long getSizeOfFolder(DirectoryInfo d) { long totalSize = 0; try { if (!FindLargestFolder.isDirectoryExcluded(d.FullName)) { //loop through any subdirs if (recurse == true) { foreach (DirectoryInfo subdir in d.GetDirectories()) { //recurse and all all subdirs try { totalSize = totalSize + getSizeOfFolder(subdir); } catch (UnauthorizedAccessException) { //ignore it.. } } } //add files from current folder FileInfo[] fiArray = d.GetFiles(); foreach (FileInfo f in fiArray) { totalSize += f.Length; } } } catch (DirectoryNotFoundException) { }; return(totalSize); }
static void Main(string[] args) { //Load all the commands in args[] into a list so that we can add to them later if we get passed a filename, foreach (String s1 in args) { commands.Add(s1); } string s = ""; if (args.Length > 0) { while (commands.Count > 0) { s = commands[0]; s.Trim(); commands.RemoveAt(0); switch (ParseMode) { //deafault mode case parseModes.Default: switch (s) { case "-x": ParseMode = parseModes.exclude; break; case "-nr": FindLargestFolder.recurse = false; break; case "-?": Help helpwindow = new Help( "Usage: \n" + "<dir>" + "\t\t" + "Search direct subdirectories of directory" + "\n" + "-c" + "\t\t" + "Choose folder after search" + "\n" + "-x <dir>" + "\t\t" + "Exclude directory" + "\n" + "-nr" + "\t\t" + "Disable recursing directories" + "\n" + "-l <filename>" + "\t" + "Load a set of commands from a file" + "\n" + "-f <foldername>" + "\t" + "Add a single folder to the list (not subdirectories)" + "\n" + "-cachestats" + "\t\t" + "Show cache / pick stats" + "\n" + "-cache <min> <max>" + "\t" + "Cache file access for min < x < max hours" + "\n" + "-cachefolder <directory>" + "\t" + "Folder where cache data should be written" + "\n" + "-cacheignore <directory>" + "\t\t" + "Never cache this folder" ); Application.Run(helpwindow); PickMode = pickModes.noPick; break; case "-c": FindLargestFolder.showChooser = true; break; case "-l": ParseMode = parseModes.loadfile; break; case "-f": ParseMode = parseModes.addSingleFolder; break; case "-cachestats": FindLargestFolder.showCacheStats = true; break; case "-cache": FindLargestFolder.useCache = true; ParseMode = parseModes.cache_min; break; case "-cachefolder": ParseMode = parseModes.cachefolder; break; case "-cacheignore": ParseMode = parseModes.cacheignore; break; default: FindLargestFolder.addPath(s); break; } break; //exclude directory mode case parseModes.exclude: ParseMode = parseModes.Default; FindLargestFolder.excludePath(s); break; case parseModes.loadfile: //load a file one row at a time into args[] ParseMode = parseModes.Default; StreamReader f = new StreamReader(s); string line; while ((line = f.ReadLine()) != null) { commands.Add(line); } break; case parseModes.addSingleFolder: //load a single folder straght into the list to check. FindLargestFolder.addDirectoryDirectly(s); break; case parseModes.cachefolder: ParseMode = parseModes.Default; FindLargestFolder.cachefolder = s; break; case parseModes.cacheignore: ParseMode = parseModes.Default; FindLargestFolder.cacheIgnoreList.Add(s); break; case parseModes.cache_min: ParseMode = parseModes.cache_max; FindLargestFolder.cacheHoursMin = Convert.ToInt32(s); break; case parseModes.cache_max: ParseMode = parseModes.Default; FindLargestFolder.cacheHoursMax = Convert.ToInt32(s); break; } } #region pickModes //keep the pick modes as if we selected pickmode.none we dont want to actually do anything here. switch (PickMode) { case pickModes.single: FindLargestFolder.scanDirectories(); if (FindLargestFolder.showChooser) { FindLargestFolder.pickChoice(); } else { FindLargestFolder.pickLargest(); } break; } #endregion } //save the cache FindLargestFolder.saveCache(); //else //{ // Application.EnableVisualStyles(); // Application.SetCompatibleTextRenderingDefault(false); // Application.Run(new Monitor()); //} }
private void listBox1_MouseDoubleClick(object sender, MouseEventArgs e) { folderAndSize f = (folderAndSize)listBox1.SelectedItem; FindLargestFolder.openFolder(f.folderPath); }
private void btn_Open_Only_Click(object sender, EventArgs e) { folderAndSize f = (folderAndSize)listBox1.SelectedItem; FindLargestFolder.openFolder(f.folderPath); }