Click here to Skip to main content
15,896,557 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.7K   5.6K   125  
File Find is fast, especially if you have multiple physical drives; version 2.1.0.17.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace FileFind
{
    public partial class DiskFileFilterLists : Form
    {
        private ConfigInfo configInfo;
        private FilterLists filterLists;
        private const string ILLEGALCHARACTERFOUND = "Selection characters (asterisk and question mark) are not allowed";

        private Point formLocation = new Point(0, 0);
        private bool formLocationSet = false;
        public Point FormLocation
        {
            get { return formLocation; }
            set { formLocation = value; formLocationSet = true; }
        }

        public DiskFileFilterLists()
        { InitializeComponent(); }

        private void DiskFileFilterLists_Load(object sender, EventArgs e)
        {
            if (formLocationSet)
                this.Location = formLocation;
            configInfo = new ConfigInfo();
            this.Font = configInfo.UseFont;
            this.Text = configInfo.ProductName + " - " + this.Text;
            label1.Text = "";
            richTextBox1.Clear();
            richTextBox1.AppendText("Select a 'filter list' to use by double clicking the list name");
            richTextBox1.AppendText(" or single click a list name and select an action.");
            filterLists = configInfo.GetFilterLists;
            PopulateListBox1();
            Application.Idle += new System.EventHandler(OnIdle);
        } //ends private void DiskFileFilterLists_Load(...

        private void OnIdle(Object sender, EventArgs e)
        {
            if (0 == filterLists.Count)
            {
                label1.Text = "No stored filter lists were found; you must create a new one.";
                ViewButton.Enabled =
                EditButton.Enabled =
                DeleteButton.Enabled = false;
            }
            else
            {
                ViewButton.Enabled =
                EditButton.Enabled =
                DeleteButton.Enabled = true;
            }
        }

        private void PopulateListBox1()
        {
            listBox1.Items.Clear();
            if (null != (filterLists = configInfo.GetFilterLists))
            {
                FilterList inUseFilterList = filterLists.GetInUse();
                if (null == inUseFilterList)
                    label1.Text = "No filter list is currently in use.";
                else
                    label1.Text = "Filter list currently in use: " + inUseFilterList.Name;
                listBox1.BeginUpdate();
                foreach (FilterList filterList in filterLists)
                    listBox1.Items.Add(filterList.Name);
                listBox1.EndUpdate();
            }
        } //ends private void PopulateListBox1()

        private void cancelButton_Click(object sender, EventArgs e)
        {   //Cancel all changes
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        private void OkButton_Click(object sender, EventArgs e)
        {   //Pass back the selection, if any
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void DeleteButton_Click(object sender, EventArgs e)
        {
            if (0 == listBox1.SelectedItems.Count)
            {
                label1.Text = "You must select a filter list name";
                return;
            }
            if (listBox1.SelectedItems.Count > 1)
            {
                label1.Text = "You may select only one filter list name";
                return;
            }
            string selectedName = listBox1.SelectedItem.ToString();
            filterLists.Remove(selectedName);
            listBox1.Items.Remove(listBox1.SelectedItem);
        }

        private void NewButton_Click(object sender, EventArgs e)
        {
            NewEditFilter newEditFilter = new NewEditFilter();
            newEditFilter.FormLocation = this.Location;
            this.Visible = false;
            newEditFilter.ShowDialog();
            if (DialogResult.OK == newEditFilter.DialogResult)
            {
                label1.Text = "Created new filter list";
                PopulateListBox1();
            }
            this.Visible = true;
        }

        private void EditButton_Click(object sender, EventArgs e)
        {
            switch (listBox1.SelectedItems.Count)
            {
                case 0:
                    label1.Text = "You must select a filter list name";
                    break;
                case 1:
                    string selectedName = listBox1.SelectedItem.ToString();
                    NewEditFilter newEditFilter = new NewEditFilter();
                    newEditFilter.FormLocation = this.Location;
                    newEditFilter.FilterName = selectedName;
                    newEditFilter.ShowDialog();
                    if (DialogResult.OK == newEditFilter.DialogResult)
                    {
                        label1.Text = "Filter list was saved";
                        PopulateListBox1();
                    }
                    else
                        label1.Text = "";
                    break;
                default:
                    label1.Text = "You may select only one filter list name";
                    break;
            }
        }

        private void ViewButton_Click(object sender, EventArgs e)
        {
            label1.Text = "Not coded";
        }

    }
}

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