Exemple #1
0
        private void AddListItemThread(object fullpath)
        {
            progressForm.Visible = true;
            progressForm.SetPosition(Left, Width, Top, Height);
            LogLabel.Text = "加载中...";
            string path = (string)fullpath;

            listView1.Items.Clear();
            try
            {
                ListViewData.Instance.ClearListItemInfo();
                DirectoryInfo   di       = new DirectoryInfo(path);
                DirectoryInfo[] dis      = di.GetDirectories();
                FileInfo[]      fis      = di.GetFiles();
                int             allfiles = dis.Length + fis.Length;
                int             index    = 0;
                foreach (var directoryInfo in dis)
                {
                    string text = string.Format("正在加载{2}  已完成{0}/{1}", index, allfiles, directoryInfo.Name);
                    LogLabel.Text = text;
                    progressForm.ShowText(text);
                    progressForm.ShowProgress(allfiles, index);
                    ListItemInfo listItemInfo = new ListItemInfo {
                        Name = directoryInfo.Name, CrtTm = directoryInfo.CreationTime, ModTm = directoryInfo.LastWriteTime, Type = "文件夹", Size = Util.GetDirectoryLength(directoryInfo.FullName)
                    };
                    AddViewItem(listItemInfo, false);
                    ListViewData.Instance.SetListItemInfo(listItemInfo, InfoType.DIRECTORY);
                    index++;
                    Thread.Sleep(10);
                }
                foreach (var fileInfo in fis)
                {
                    string text = string.Format("正在加载{2}  已完成{0}/{1}", index, allfiles, fileInfo.Name);
                    LogLabel.Text = text;
                    LogLabel.Text = text;
                    progressForm.ShowText(text);
                    progressForm.ShowProgress(allfiles, index);
                    ListItemInfo listItemInfo = new ListItemInfo {
                        Name = fileInfo.Name, CrtTm = fileInfo.CreationTime, ModTm = fileInfo.LastWriteTime, Type = fileInfo.Extension.Replace(".", "").ToUpper() + "文件", Size = Util.FileSize(fileInfo.FullName)
                    };
                    AddViewItem(listItemInfo);
                    ListViewData.Instance.SetListItemInfo(listItemInfo, InfoType.File);
                    index++;
                    Thread.Sleep(10);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            LogLabel.Text        = "加载完成";
            progressForm.Visible = false;
        }
Exemple #2
0
        private void RightMenuItemClick(object sender, EventArgs e)
        {
            if (sender is ToolStripItem)
            {
                ToolStripItem toolStripItem = (ToolStripItem)sender;
                var           items         = listView1.SelectedItems;
                foreach (var item in items)
                {
                    ListViewItem    li                  = (ListViewItem)item;
                    bool            isDirec             = false;
                    DirectoryInfo   selectDirectoryInfo = null;
                    FileInfo        selectFileInfo      = null;
                    DirectoryInfo   di                  = new DirectoryInfo(CurSelectNode.FullPath);
                    DirectoryInfo[] dis                 = di.GetDirectories();
                    foreach (var directory in dis)
                    {
                        if (directory.Name == li.Text)
                        {
                            isDirec             = true;
                            selectDirectoryInfo = directory;
                            break;
                        }
                    }
                    if (!isDirec)
                    {
                        FileInfo[] fis = di.GetFiles();
                        foreach (var fileInfo in fis)
                        {
                            if (fileInfo.Name == li.Text)
                            {
                                selectFileInfo = fileInfo;
                                break;
                            }
                        }
                    }
                    switch (toolStripItem.Text)
                    {
                    case "属性":
                        if (isDirec)
                        {
                            MessageBox.Show("详细属性:\n" +
                                            "名称:" + selectDirectoryInfo.Name + "\n" +
                                            "类型:文件夹\n" +
                                            "位置:" + selectDirectoryInfo.FullName + "\n" +
                                            "大小:" + Util.FormatSize(Util.GetDirectoryLength(selectDirectoryInfo.FullName)) + "\n" +
                                            "创建时间:" + selectDirectoryInfo.CreationTime.ToString("yyyy年MM月dd日,HH:MM:ss") + "\n" +
                                            "最后修改时间:" + selectDirectoryInfo.LastWriteTime.ToString("yyyy年MM月dd日,HH:MM:ss") + "\n" +
                                            "最后访问时间:" + selectDirectoryInfo.LastAccessTime.ToString("yyyy年MM月dd日,HH:MM:ss"),
                                            selectDirectoryInfo.Name + "属性",
                                            MessageBoxButtons.OK,
                                            MessageBoxIcon.Information);
                        }
                        else
                        {
                            MessageBox.Show("详细属性:\n" +
                                            "名称:" + selectFileInfo.Name + "\n" +
                                            "类型:" + selectFileInfo.Extension.Replace(".", "").ToUpper() + "文件(" + selectFileInfo.Extension + ")" + "\n" +
                                            "位置:" + selectFileInfo.FullName + "\n" +
                                            "大小:" + Util.FormatSize(Util.GetDirectoryLength(selectFileInfo.FullName)) + "\n" +
                                            "创建时间:" + selectFileInfo.CreationTime.ToString("yyyy年MM月dd日,HH:MM:ss") + "\n" +
                                            "最后修改时间:" + selectFileInfo.LastWriteTime.ToString("yyyy年MM月dd日,HH:MM:ss") + "\n" +
                                            "最后访问时间:" + selectFileInfo.LastAccessTime.ToString("yyyy年MM月dd日,HH:MM:ss"),
                                            selectFileInfo.Name + "属性",
                                            MessageBoxButtons.OK,
                                            MessageBoxIcon.Information);
                        }
                        break;

                    case "删除":
                        if (isDirec)
                        {
                            DialogResult dr = MessageBox.Show("确定是否删除文件夹" + selectDirectoryInfo.Name + "?", "文件夹删除",
                                                              MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                            if (dr == DialogResult.OK)
                            {
                                try
                                {
                                    selectDirectoryInfo.Delete();
                                }
                                catch (Exception ee)
                                {
                                    MessageBox.Show(ee.Message, "删除失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                }
                            }
                        }
                        else
                        {
                            DialogResult dr = MessageBox.Show("确定是否删除文件" + selectFileInfo.Name + "?", "文件删除",
                                                              MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                            if (dr == DialogResult.OK)
                            {
                                try
                                {
                                    selectFileInfo.Delete();
                                }
                                catch (Exception ee)
                                {
                                    MessageBox.Show(ee.Message, "删除失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                }
                                finally
                                {
                                    RefreshViewList(CurSelectNode.TreeNode);
                                }
                            }
                        }
                        break;
                    }
                }
            }
        }
Exemple #3
0
        private void TreeViewAfterSelect(object sender, TreeViewEventArgs e)
        {
            TreeNode node = e.Node;

            if (node.FullPath == "我的电脑")//当前选择了我的电脑根目录
            {
                currentFolderType = FolderType.COMPUTER;

                InitListViewDrive();
                listView1.Items.Clear();
                DriveInfo[] allDirves = DriveInfo.GetDrives();
                //检索计算机上的所有逻辑驱动器名称
                foreach (DriveInfo item in allDirves)
                {
                    //Fixed 硬盘
                    //Removable 可移动存储设备,如软盘驱动器或USB闪存驱动器。
                    if (item.IsReady)
                    {
                        string driveName = string.Format("{0} ({1})", item.VolumeLabel, item.Name.Replace("\\", ""));

                        ListViewItem li = new ListViewItem();
                        li.Text       = driveName;
                        li.ImageIndex = (int)ImageFileType.DRIVE;
                        li.SubItems.Add(item.DriveFormat);
                        li.SubItems.Add(Util.FormatSize(item.TotalSize));
                        li.SubItems.Add(Util.FormatSize(item.TotalSize - item.TotalFreeSpace));
                        li.SubItems.Add(Util.FormatSize(item.TotalFreeSpace));
                        if (item.TotalFreeSpace * 10 < item.TotalSize)//剩余空间不足10%背景显示红色
                        {
                            li.BackColor = Color.Red;
                        }
                        listView1.Items.Add(li);
                    }
                    else
                    {
                        Console.Write("没有就绪");
                    }
                }
            }
            else
            {
                InitListView();
                bool        isdriveRoot = false;
                DriveInfo[] allDirves   = DriveInfo.GetDrives();
                //检索计算机上的所有逻辑驱动器名称
                foreach (DriveInfo item in allDirves)
                {
                    string driveName = string.Format("{0} ({1})", item.VolumeLabel, item.Name.Replace("\\", ""));
                    if (node.Text == driveName)
                    {
                        currentFolderType = FolderType.Driver;
                        AddListItemByFullPath(item.Name);
                        isdriveRoot = true;
                        break;
                    }
                }
                if (!isdriveRoot && treeNodeDic.ContainsKey(node.FullPath) && (CurSelectNode == null || CurSelectNode.TreeNode != node))
                {
                    CurSelectNode     = treeNodeDic[node.FullPath];
                    currentFolderType = FolderType.DIRECTORY;
                    AddListItem(node);
                }
            }
        }