Ejemplo n.º 1
0
        private void btnMax_Click(object sender, EventArgs e)
        {
            try
            {
                filePath = txtBoxPath.Text;

                // Check whether the file path is empty
                if (String.IsNullOrEmpty(filePath))
                {
                    MessageBox.Show("Please choose the file folder first!");
                    return;
                }

                // Get the largest files by the LargestFiles extension method
                var largestFileLists = LinqToFileSystem.GetFiles(filePath).
                                       LargestFiles();

                // Display the data
                if (largestFileLists.Count() > 0)
                {
                    string text = String.Format("{0} file(s) with max length {1} bytes:", largestFileLists.Count(), largestFileLists.First().Length);

                    foreach (var file in largestFileLists)
                    {
                        text += "\r\n" + file.Name;
                    }

                    MessageBox.Show(text);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Ejemplo n.º 2
0
        private void btnGroup_Click(object sender, EventArgs e)
        {
            try
            {
                filePath = txtBoxPath.Text;

                // Check whether the file path is empty
                if (String.IsNullOrEmpty(filePath))
                {
                    MessageBox.Show("Please choose the file folder first!");
                    return;
                }

                // Get the all the files under the folder by the GetFiles
                // extension methods, then group the files by the extension
                // names.
                var queryGroupByExt =
                    from file in LinqToFileSystem.GetFiles(filePath)
                    group file by file.Extension.ToLower() into fileGroup
                    orderby fileGroup.Key
                    select fileGroup;

                // Display the files in TreeView
                foreach (var fg in queryGroupByExt)
                {
                    TreeNode node = treeView1.Nodes.Add(fg.Key);
                    foreach (var f in fg)
                    {
                        node.Nodes.Add(f.Name);
                    }
                }

                treeView1.ExpandAll();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }