コード例 #1
0
        //初始化tagArray和folderArray数组,
        private void initArray(String path, DirectoryInfo rootPath)
        {
            if (FolderArray.Count != 0)
            {
                FolderArray.Clear();
            }
            if (tagArray.Count != 0)
            {
                tagArray.Clear();//清空两个数组
            }
            //遍历path下的所有文件夹
            foreach (DirectoryInfo NextFolder in rootPath.GetDirectories())
            {
                //判别该文件夹是否被系统保护,若是则不创建其相对的folder类
                DirectorySecurity s = new DirectorySecurity(path + "\\" + NextFolder.Name, AccessControlSections.Access);
                if (!s.AreAccessRulesProtected)
                {
                    Folder folder = new Folder(path, NextFolder.Name);
                    FolderArray.Add(folder);
                    //将该Folder类中的所有tag加入tagArray数组中,留待以后进行消除重复的操作
                    foreach (string tag in folder.tagArray)
                    {
                        Tag t = new TagManager.Tag(tag);
                        tagArray.Add(t);
                    }
                    folder = null;
                }
            }

            tagArray = RemoveDuplicate_Tag(tagArray);//清除重复元素
            //制作ALLtag类,用于存放所有folder的索引
            Tag t1 = new TagManager.Tag("所有文件夹");

            for (int i = 0; i < FolderArray.Count; i++)
            {
                t1.pushFolder(i);
                Folder f = (Folder)FolderArray[i]; //取出当前Folder类
                for (int j = 0; j < tagArray.Count; j++)
                {                                  //将当前Folder类与tagArray数组进行逐个比较,若符合则将其索引加入该Tag类
                    Tag tag = (Tag)tagArray[j];
                    if (f.tagArray.Contains(tag.tagName))
                    {
                        tag.pushFolder(i);
                    }
                }
            }
            tagArray.Insert(0, t1);
            TagCountLabel.Text    = "共有 " + tagArray.Count + " 项标签";
            FolderCountLabel.Text = FolderArray.Count + "个项目";
        }
コード例 #2
0
        //打开一个资源管理器,从中选择操作根目录
        private void 指定操作根目录ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (FolderArray.Count != 0)
            {
                FolderArray.Clear();
            }
            if (tagArray.Count != 0)
            {
                tagArray.Clear();//清空两个数组
            }
            FolderBrowserDialog openFile = new FolderBrowserDialog();

            openFile.ShowDialog();
            String        path     = openFile.SelectedPath;//被选中的目录路径赋给path
            DirectoryInfo rootPath = new DirectoryInfo(path);

            //遍历path下的所有文件夹
            foreach (DirectoryInfo NextFolder in rootPath.GetDirectories())
            {
                //判别该文件夹是否被系统保护,若是则不创建其相对的folder类
                DirectorySecurity s = new DirectorySecurity(path + "\\" + NextFolder.Name, AccessControlSections.Access);
                if (!s.AreAccessRulesProtected)
                {
                    Folder folder = new Folder(path, NextFolder.Name);
                    FolderArray.Add(folder);
                    //将该Folder类中的所有tag加入tagArray数组中,留待以后进行消除重复的操作
                    foreach (string tag in folder.tagArray)
                    {
                        Tag t = new TagManager.Tag(tag);
                        tagArray.Add(t);
                    }
                    folder = null;
                }
            }

            tagArray = RemoveDuplicate_Tag(tagArray);//清除重复元素
            //制作ALLtag类,用于存放所有folder的索引
            Tag t1 = new TagManager.Tag("All");

            for (int i = 0; i < FolderArray.Count; i++)
            {
                t1.pushFolder(i);
                Folder f = (Folder)FolderArray[i];       //取出当前Folder类
                for (int j = 0; j < tagArray.Count; j++) //将当前Folder类与tagArray数组进行逐个比较,若符合则将其索引加入该Tag类
                {
                    Tag tag = (Tag)tagArray[j];
                    if (f.tagArray.Contains(tag.tagName))
                    {
                        tag.pushFolder(i);
                    }
                }
            }
            tagArray.Insert(0, t1);
            Folder_listBox.Items.Clear();
            Tag_listBox.Items.Clear();
            //往两个listbox中添加项
            foreach (Folder nextFolder in FolderArray)
            {
                Folder_listBox.Items.Add(nextFolder.folderName);
                this.Folder_listBox.Focus();
            }
            foreach (Tag nextTag in tagArray)
            {
                Tag_listBox.Items.Add(nextTag.tagName);
            }
        }