Exemplo n.º 1
0
        private void button5_Click(object sender, EventArgs e)
        {
            IFilter filter  = new StringFilter();
            bool    isMatch = filter.match("6.21苏宁云商.jpg", "苏宁+易购,云商");

            Console.WriteLine(isMatch);
        }
Exemplo n.º 2
0
        private void 分类ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TreeNode node = this.treeView1.SelectedNode;

            if (node == null)
            {
                MessageBox.Show("请选择文件夹");
                return;
            }

            if (MessageBox.Show("按过滤条件进行文件分类,如果文件名出现同名,将覆盖,是否确定继续?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
            {
                NodeData      data = node.Tag as NodeData;
                string        path = data.path;
                DirectoryInfo dir  = new DirectoryInfo(path);
                if (!dir.Exists)
                {
                    dir.Create();
                }


                string  filterStr = data.filter;
                IFilter filter    = new StringFilter();


                int count = 0;
                foreach (var obj in this.listBox1.Items)
                {
                    Item item = obj as Item;
                    if (item == null)
                    {
                        continue;
                    }
                    try
                    {
                        bool isMatch = filter.match(item.text, filterStr);
                        if (isMatch)
                        {
                            File.Copy(item.value, path + "\\" + item.text, true);
                            count++;
                        }
                    }
                    catch (Exception ex)
                    {
                        continue;
                    }
                }

                MessageBox.Show("分类完成,已经归类了" + count + "个文件");
            }
        }