Click here to Skip to main content
15,891,762 members
Articles / Programming Languages / C#

Multithreaded File/Folder Finder

Rate me:
Please Sign up or sign in to vote.
4.19/5 (18 votes)
26 May 2010CPOL17 min read 110.5K   5.6K   125  
File Find is fast, especially if you have multiple physical drives; version 2.1.0.17.
using System;
using System.Management;
using System.Security.Principal;
using System.Text;
using System.Threading;
using System.Windows.Forms;

namespace FileFind
{
    /// <summary>
    /// Displays the About information for the File Find application
    /// </summary>
    public partial class About : Form
    {
        public About()
        { InitializeComponent(); }

        /// <summary>
        /// Appends the word(s) in str to the StringBuilder
        /// Each new set of str is separated from the prior set by a comma
        /// </summary>
        /// <param name="sb">StringBuilder output field</param>
        /// <param name="str">String to be appended to the sb field</param>
        private void AddRole(ref StringBuilder sb, string str)
        {   //creates a string of words separated by commas
            if (sb.Length > 1)
                sb.Append(", " + str);
            else
                sb.Append(str);
        }

        private void About_Load(object sender, EventArgs e)
        {
            ConfigInfo configInfo = new ConfigInfo();
            this.Font = configInfo.UseFont;
            this.Text = "About " + configInfo.ProductName;
            productInfoLabel.Text =
                configInfo.ProductName 
                + " - Version " + configInfo.ProductVersion
                + "  " + configInfo.ProductDate;

            AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
            WindowsPrincipal principal = (WindowsPrincipal)Thread.CurrentPrincipal;
            WindowsIdentity identity = (WindowsIdentity)principal.Identity;
            StringBuilder sysrole = new StringBuilder();
            sysrole.Append("(");
            if (principal.IsInRole(WindowsBuiltInRole.AccountOperator))
                AddRole(ref sysrole, "account operator");
            if (principal.IsInRole(WindowsBuiltInRole.Administrator))
                AddRole(ref sysrole, "administrator");
            if (principal.IsInRole(WindowsBuiltInRole.BackupOperator))
                AddRole(ref sysrole, "backup operator");
            if (principal.IsInRole(WindowsBuiltInRole.Guest))
                AddRole(ref sysrole, "guest");
            if (principal.IsInRole(WindowsBuiltInRole.PowerUser))
                AddRole(ref sysrole, "power user");
            if (principal.IsInRole(WindowsBuiltInRole.PrintOperator))
                AddRole(ref sysrole, "print operator");
            if (principal.IsInRole(WindowsBuiltInRole.Replicator))
                AddRole(ref sysrole, "replicator");
            if (principal.IsInRole(WindowsBuiltInRole.SystemOperator))
                AddRole(ref sysrole, "system operator");
            if (principal.IsInRole(WindowsBuiltInRole.User))
                AddRole(ref sysrole, "user");
            sysrole.Append(")");
            useridLabel.Text = "User: " + Environment.UserName + " " + sysrole;

            machineName.Text = "Machine name: " + Environment.MachineName;

            OSVersionLabel.Text = Environment.OSVersion.ToString();

            CLRVersionLabel.Text = "CLR Version " + Environment.Version.ToString();

            processorInfoLabel.Text = Environment.GetEnvironmentVariable("processor_identifier");

            string[] logical_drives = Environment.GetLogicalDrives();
            processorIdLabel.Text = "System has " + Environment.ProcessorCount + " processors and "
             + logical_drives.Length.ToString() + " logical disks";

            string str = null;
            ManagementObjectSearcher objCS = new ManagementObjectSearcher("SELECT * FROM Win32_ComputerSystem");
            foreach (ManagementObject objMgmt in objCS.Get())
            { str = objMgmt["totalphysicalmemory"].ToString(); }
            long physmem = Convert.ToInt64(str);
            systemRAMLabel.Text = "Physical memory " + physmem.ToString("N0") + " bytes";
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) retired
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions