diff --git a/FindLargestFolders.sln b/FindLargestFolders.sln new file mode 100644 index 0000000..37f4e9b --- /dev/null +++ b/FindLargestFolders.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.28803.156 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FindLargestFolders", "FindLargestFolders\FindLargestFolders.csproj", "{343451B4-1181-4804-A69D-EA9D3AB74596}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {343451B4-1181-4804-A69D-EA9D3AB74596}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {343451B4-1181-4804-A69D-EA9D3AB74596}.Debug|Any CPU.Build.0 = Debug|Any CPU + {343451B4-1181-4804-A69D-EA9D3AB74596}.Release|Any CPU.ActiveCfg = Release|Any CPU + {343451B4-1181-4804-A69D-EA9D3AB74596}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {97DA4E3C-4C9E-4CD0-94D9-076E61473504} + EndGlobalSection +EndGlobal diff --git a/FindLargestFolders/App.config b/FindLargestFolders/App.config new file mode 100644 index 0000000..bae5d6d --- /dev/null +++ b/FindLargestFolders/App.config @@ -0,0 +1,6 @@ + + + + + + diff --git a/FindLargestFolders/DirectoryItemUI.Designer.cs b/FindLargestFolders/DirectoryItemUI.Designer.cs new file mode 100644 index 0000000..896d13f --- /dev/null +++ b/FindLargestFolders/DirectoryItemUI.Designer.cs @@ -0,0 +1,114 @@ +namespace FindLargestFolders +{ + partial class DirectoryItemUI + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.label1 = new System.Windows.Forms.Label(); + this.button1 = new System.Windows.Forms.Button(); + this.label2 = new System.Windows.Forms.Label(); + this.button2 = new System.Windows.Forms.Button(); + this.belowFlow = new System.Windows.Forms.FlowLayoutPanel(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(57, 22); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(42, 13); + this.label1.TabIndex = 0; + this.label1.Text = "DirPath"; + // + // button1 + // + this.button1.Location = new System.Drawing.Point(3, 13); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(30, 31); + this.button1.TabIndex = 1; + this.button1.Text = "+"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.Button1_Click); + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(434, 22); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(40, 13); + this.label2.TabIndex = 2; + this.label2.Text = "DirSize"; + // + // button2 + // + this.button2.Location = new System.Drawing.Point(39, 13); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(12, 31); + this.button2.TabIndex = 3; + this.button2.Text = "S"; + this.button2.UseVisualStyleBackColor = true; + this.button2.Click += new System.EventHandler(this.Button2_Click); + // + // belowFlow + // + this.belowFlow.AutoScroll = true; + this.belowFlow.AutoSize = true; + this.belowFlow.Location = new System.Drawing.Point(23, 44); + this.belowFlow.MaximumSize = new System.Drawing.Size(884, 10000); + this.belowFlow.Name = "belowFlow"; + this.belowFlow.Size = new System.Drawing.Size(477, 0); + this.belowFlow.TabIndex = 4; + // + // DirectoryItemUI + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.AutoSize = true; + this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.BackColor = System.Drawing.Color.SteelBlue; + this.Controls.Add(this.belowFlow); + this.Controls.Add(this.button2); + this.Controls.Add(this.label2); + this.Controls.Add(this.button1); + this.Controls.Add(this.label1); + this.MaximumSize = new System.Drawing.Size(884, 10000); + this.Name = "DirectoryItemUI"; + this.Size = new System.Drawing.Size(503, 47); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Button button1; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Button button2; + private System.Windows.Forms.FlowLayoutPanel belowFlow; + } +} diff --git a/FindLargestFolders/DirectoryItemUI.cs b/FindLargestFolders/DirectoryItemUI.cs new file mode 100644 index 0000000..ad6a3d7 --- /dev/null +++ b/FindLargestFolders/DirectoryItemUI.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using System.IO; + +namespace FindLargestFolders +{ + public partial class DirectoryItemUI : UserControl + { + public delegate void ExtendClickedEventDelegate(DirectoryInfo dir); + public event ExtendClickedEventDelegate ExtendedClickEvent; + public event ExtendClickedEventDelegate ScanClickEvent; + public DirectoryInfo Dir; + private bool isExtended = false; + public DirectoryItemUI(DirectoryInfo directory,string size,bool isParent) + { + Dir = directory; + InitializeComponent(); + label1.Text = directory.FullName; + label2.Text = size; + if (!isParent) button2.Visible = false; + } + public void SetDirSize(string size) + { + label2.Text = size; + } + private void Button1_Click(object sender, EventArgs e) + { + if (isExtended) + { + button1.Text = "+"; + belowFlow.Controls.Clear(); + isExtended = false; + } + else + { + button1.Text = "-"; + ExtendedClickEvent?.Invoke(Dir); + isExtended = true; + } + } + + private void Button2_Click(object sender, EventArgs e) + { + ScanClickEvent?.Invoke(Dir); + } + public void AddLayout(DirectoryItemUI ui) + { + belowFlow.Controls.Add(ui); + } + public void RemoveLayout(DirectoryItemUI ui) + { + belowFlow.Controls.Remove(ui); + } + } +} diff --git a/FindLargestFolders/DirectoryItemUI.resx b/FindLargestFolders/DirectoryItemUI.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/FindLargestFolders/DirectoryItemUI.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/FindLargestFolders/FindLargestFolders.csproj b/FindLargestFolders/FindLargestFolders.csproj new file mode 100644 index 0000000..d1b15e7 --- /dev/null +++ b/FindLargestFolders/FindLargestFolders.csproj @@ -0,0 +1,136 @@ + + + + + Debug + AnyCPU + {343451B4-1181-4804-A69D-EA9D3AB74596} + WinExe + FindLargestFolders + FindLargestFolders + v4.6.1 + 512 + true + true + false + C:\Users\baz\OneDrive\FLF\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 1 + 1.0.0.%2a + false + true + true + + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + D0C4D5B227DE1AD552EBB684F1A8F84A2F477C79 + + + FindLargestFolders_TemporaryKey.pfx + + + true + + + true + + + + + + + + + + + + + + + + + UserControl + + + DirectoryItemUI.cs + + + Form + + + Form1.cs + + + + + + DirectoryItemUI.cs + + + Form1.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + True + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + False + Microsoft .NET Framework 4.8 %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 + false + + + + \ No newline at end of file diff --git a/FindLargestFolders/Form1.Designer.cs b/FindLargestFolders/Form1.Designer.cs new file mode 100644 index 0000000..382284c --- /dev/null +++ b/FindLargestFolders/Form1.Designer.cs @@ -0,0 +1,142 @@ +namespace FindLargestFolders +{ + partial class Form1 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.comboBox1 = new System.Windows.Forms.ComboBox(); + this.label1 = new System.Windows.Forms.Label(); + this.button1 = new System.Windows.Forms.Button(); + this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel(); + this.backgroundWorker1 = new System.ComponentModel.BackgroundWorker(); + this.label2 = new System.Windows.Forms.Label(); + this.numericUpDown1 = new System.Windows.Forms.NumericUpDown(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit(); + this.SuspendLayout(); + // + // comboBox1 + // + this.comboBox1.FormattingEnabled = true; + this.comboBox1.Location = new System.Drawing.Point(98, 12); + this.comboBox1.Name = "comboBox1"; + this.comboBox1.Size = new System.Drawing.Size(121, 21); + this.comboBox1.TabIndex = 1; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(13, 15); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(65, 13); + this.label1.TabIndex = 2; + this.label1.Text = "Select Drive"; + // + // button1 + // + this.button1.Location = new System.Drawing.Point(533, 12); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(136, 23); + this.button1.TabIndex = 3; + this.button1.Text = "Start"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.Button1_Click); + // + // flowLayoutPanel1 + // + this.flowLayoutPanel1.AutoScroll = true; + this.flowLayoutPanel1.Location = new System.Drawing.Point(15, 39); + this.flowLayoutPanel1.Name = "flowLayoutPanel1"; + this.flowLayoutPanel1.Size = new System.Drawing.Size(884, 399); + this.flowLayoutPanel1.TabIndex = 4; + // + // backgroundWorker1 + // + this.backgroundWorker1.WorkerReportsProgress = true; + this.backgroundWorker1.DoWork += new System.ComponentModel.DoWorkEventHandler(this.BackgroundWorker1_DoWork); + this.backgroundWorker1.ProgressChanged += new System.ComponentModel.ProgressChangedEventHandler(this.BackgroundWorker1_ProgressChanged); + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(323, 15); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(93, 13); + this.label2.TabIndex = 5; + this.label2.Text = "Max No of Folders"; + // + // numericUpDown1 + // + this.numericUpDown1.Location = new System.Drawing.Point(423, 12); + this.numericUpDown1.Maximum = new decimal(new int[] { + 50, + 0, + 0, + 0}); + this.numericUpDown1.Minimum = new decimal(new int[] { + 1, + 0, + 0, + 0}); + this.numericUpDown1.Name = "numericUpDown1"; + this.numericUpDown1.Size = new System.Drawing.Size(45, 20); + this.numericUpDown1.TabIndex = 6; + this.numericUpDown1.Value = new decimal(new int[] { + 10, + 0, + 0, + 0}); + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(911, 450); + this.Controls.Add(this.numericUpDown1); + this.Controls.Add(this.label2); + this.Controls.Add(this.flowLayoutPanel1); + this.Controls.Add(this.button1); + this.Controls.Add(this.label1); + this.Controls.Add(this.comboBox1); + this.Name = "Form1"; + this.Text = "BazWare FLF - Find Large Folders"; + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + private System.Windows.Forms.ComboBox comboBox1; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Button button1; + private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1; + private System.ComponentModel.BackgroundWorker backgroundWorker1; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.NumericUpDown numericUpDown1; + } +} + diff --git a/FindLargestFolders/Form1.cs b/FindLargestFolders/Form1.cs new file mode 100644 index 0000000..3fe7660 --- /dev/null +++ b/FindLargestFolders/Form1.cs @@ -0,0 +1,95 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace FindLargestFolders +{ + + public partial class Form1 : Form + { + Dictionary directoryUI = new Dictionary(); + public Form1() + { + InitializeComponent(); + var drives = Utilities.GetDrives(); + comboBox1.Text = drives[0].Name; + foreach (var drive in drives) + { + comboBox1.Items.Add(drive.Name); + } + } + + private void BackgroundWorker1_DoWork(object sender, DoWorkEventArgs e) + { + + } + + private void BackgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e) + { + + } + + private void Button1_Click(object sender, EventArgs e) + { + var givenPath = new DirectoryInfo(comboBox1.Text); + flowLayoutPanel1.Controls.Clear(); + foreach (var dir in givenPath.GetDirectories()) + { + var uiComponent = new DirectoryItemUI(dir, "0",true); + uiComponent.ExtendedClickEvent += UiComponent_ExtendedClickEvent; + uiComponent.ScanClickEvent += UiComponent_ScanClickEvent; + uiComponent.Name = dir.FullName; + directoryUI.Add(dir, uiComponent); + flowLayoutPanel1.Controls.Add(uiComponent); + } + + } + + private void UiComponent_ScanClickEvent(DirectoryInfo dir) + { + var dirs = dir.GetDirectories(); + var dirSize = Utilities.FormatBytes(Utilities.GetDirSize(dir)); + directoryUI[dir].SetDirSize(dirSize); + } + + private void UiComponent_ExtendedClickEvent(DirectoryInfo dir) + { + int numberofDirsToShow = (int)numericUpDown1.Value; + Dictionary dirSizeMap = new Dictionary(); + List dirSizes = new List(); + + var dirs = dir.GetDirectories(); + foreach (var ldir in dirs) + { + long dirSize = Utilities.GetDirSize(ldir); + if (dirSize > 0) + { + if (!dirSizeMap.ContainsKey(dirSize)) + { + dirSizeMap.Add(dirSize, ldir); + dirSizes.Add(dirSize); + } + } + } + dirSizes.Sort(); + if (dirSizes.Count < numberofDirsToShow) numberofDirsToShow = dirSizes.Count; + for(int i= dirSizes.Count -1; i > (dirSizes.Count - numberofDirsToShow-1);--i) + { + var ldir = dirSizeMap[dirSizes[i]]; + var uiComponent = new DirectoryItemUI(ldir, Utilities.FormatBytes(dirSizes[i]),false); + uiComponent.ExtendedClickEvent += UiComponent_ExtendedClickEvent; + uiComponent.ScanClickEvent += UiComponent_ScanClickEvent; + uiComponent.Name = dir.FullName; + directoryUI.Add(ldir, uiComponent); + directoryUI[dir].AddLayout(uiComponent); + } + } + } +} diff --git a/FindLargestFolders/Form1.resx b/FindLargestFolders/Form1.resx new file mode 100644 index 0000000..59099f2 --- /dev/null +++ b/FindLargestFolders/Form1.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/FindLargestFolders/Program.cs b/FindLargestFolders/Program.cs new file mode 100644 index 0000000..f7d25a3 --- /dev/null +++ b/FindLargestFolders/Program.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace FindLargestFolders +{ + static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Form1()); + } + } +} diff --git a/FindLargestFolders/Properties/AssemblyInfo.cs b/FindLargestFolders/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..0df1e54 --- /dev/null +++ b/FindLargestFolders/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("FindLargestFolders")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("FindLargestFolders")] +[assembly: AssemblyCopyright("Copyright © 2019")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("343451b4-1181-4804-a69d-ea9d3ab74596")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/FindLargestFolders/Properties/Resources.Designer.cs b/FindLargestFolders/Properties/Resources.Designer.cs new file mode 100644 index 0000000..6b5ba61 --- /dev/null +++ b/FindLargestFolders/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace FindLargestFolders.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("FindLargestFolders.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/FindLargestFolders/Properties/Resources.resx b/FindLargestFolders/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/FindLargestFolders/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/FindLargestFolders/Properties/Settings.Designer.cs b/FindLargestFolders/Properties/Settings.Designer.cs new file mode 100644 index 0000000..68ca77e --- /dev/null +++ b/FindLargestFolders/Properties/Settings.Designer.cs @@ -0,0 +1,26 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace FindLargestFolders.Properties { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.3.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + } +} diff --git a/FindLargestFolders/Properties/Settings.settings b/FindLargestFolders/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/FindLargestFolders/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/FindLargestFolders/Utilities.cs b/FindLargestFolders/Utilities.cs new file mode 100644 index 0000000..80a0128 --- /dev/null +++ b/FindLargestFolders/Utilities.cs @@ -0,0 +1,65 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FindLargestFolders +{ + public class Utilities + { + public static DriveInfo[] GetDrives() + { + return DriveInfo.GetDrives(); + } + public static long GetDirSize(DirectoryInfo d) + { + long size = 0; + // Add file sizes. + try + { + FileInfo[] fis = d.GetFiles(); + foreach (FileInfo fi in fis) + { + size += fi.Length; + } + } + catch (UnauthorizedAccessException e) + { + return 0; + } + // Add subdirectory sizes. + DirectoryInfo[] dis = d.GetDirectories(); + foreach (DirectoryInfo di in dis) + { + size += GetDirSize(di); + } + return size; + } + public static long GetTotalFileSizeInDirectory(DirectoryInfo d) + { + long size = 0; + // Add file sizes. + FileInfo[] fis = d.GetFiles(); + foreach (FileInfo fi in fis) + { + size += fi.Length; + } + return size; + } + public static string FormatBytes(long bytes) + { + string[] Suffix = { "B", "KB", "MB", "GB", "TB" }; + int i; + double dblSByte = bytes; + for (i = 0; i < Suffix.Length && bytes >= 1024; i++, bytes /= 1024) + { + dblSByte = bytes / 1024.0; + } + + return String.Format("{0:0.##} {1}", dblSByte, Suffix[i]); + } + + } +}