Exemple #1
0
        private void AddSearchResultItemIntoList(string fullPath, bool isFile)
        {
            //MessageBox.Show("s");
            //是文件
            listView1.BeginUpdate();

            listView1.Items.Clear();
            if (isFile)
            {
                //MessageBox.Show("s");
                FileInfo     fileInfo = new FileInfo(fullPath);
                ListViewItem item     = listView1.Items.Add(fileInfo.Name);
                //MessageBox.Show("s");

                if (fileInfo.Extension == ".exe" || fileInfo.Extension == "")
                {
                    //通过当前系统获得文件相应图标
                    Icon fileIcon = GetSystemIcon.GetIconByFileName(fileInfo.FullName);

                    //因为不同的exe文件一般图标都不相同,所以不能按拓展名存取图标,应按文件名存取图标
                    imageList1.Images.Add(fileInfo.Name, fileIcon);

                    item.ImageKey = fileInfo.Name;
                }

                else
                {
                    if (!imageList1.Images.ContainsKey(fileInfo.Extension))
                    {
                        Icon fileIcon = GetSystemIcon.GetIconByFileName(fileInfo.FullName);

                        imageList1.Images.Add(fileInfo.Extension, fileIcon);
                    }

                    item.ImageKey = fileInfo.Extension;
                }

                item.Tag = fileInfo.FullName;

                item.SubItems.Add(fileInfo.LastWriteTimeUtc.ToString());
                item.SubItems.Add(fileInfo.Extension + "文件");
                item.SubItems.Add(ShowFileSize(fileInfo.Length).Split('(')[0]);
            }
            //是文件夹
            else
            {
                MessageBox.Show("s");
                DirectoryInfo dirInfo = new DirectoryInfo(fullPath);
                ListViewItem  item    = listView1.Items.Add(dirInfo.Name, IconsIndexes.Folder);
                item.Tag = dirInfo.FullName;
                item.SubItems.Add(dirInfo.LastWriteTimeUtc.ToString());
                item.SubItems.Add("文件夹");
                item.SubItems.Add("");
            }
            listView1.EndUpdate();
        }
Exemple #2
0
        public void ShowFilesList(string path, bool isRecord)
        {
            //tsbtnBack.Enabled = true;

            /*if (isRecord)
             * {
             *
             *  DoublyLinkedListNode newNode = new DoublyLinkedListNode();
             *  newNode.Path = path;
             *  curPathNode.NextNode = newNode;
             *  newNode.PreNode = curPathNode;
             *
             *  curPathNode = newNode;
             * }*/

            //MessageBox.Show("s");
            listView1.BeginUpdate();

            listView1.Items.Clear();
            try
            {
                DirectoryInfo   directoryInfo  = new DirectoryInfo(path);
                DirectoryInfo[] directoryInfos = directoryInfo.GetDirectories();
                FileInfo[]      fileInfos      = directoryInfo.GetFiles();

                foreach (ListViewItem item in listView1.Items)
                {
                    if (item.Text.EndsWith(".exe"))
                    {
                        imageList1.Images.RemoveByKey(item.Text);
                    }
                }


                foreach (DirectoryInfo dirInfo in directoryInfos)
                {
                    ListViewItem item = listView1.Items.Add(dirInfo.Name, IconsIndexes.Folder);
                    item.Tag = dirInfo.FullName;
                    item.SubItems.Add(dirInfo.LastWriteTime.ToString());
                    item.SubItems.Add("文件夹");
                    item.SubItems.Add("");
                }


                foreach (FileInfo fileInfo in fileInfos)
                {
                    ListViewItem item = listView1.Items.Add(fileInfo.Name);


                    if (fileInfo.Extension == ".exe" || fileInfo.Extension == "")
                    {
                        Icon fileIcon = GetSystemIcon.GetIconByFileName(fileInfo.FullName);

                        imageList1.Images.Add(fileInfo.Name, fileIcon);

                        item.ImageKey = fileInfo.Name;
                    }

                    else
                    {
                        if (!imageList1.Images.ContainsKey(fileInfo.Extension))
                        {
                            Icon fileIcon = GetSystemIcon.GetIconByFileName(fileInfo.FullName);

                            imageList1.Images.Add(fileInfo.Extension, fileIcon);
                        }

                        item.ImageKey = fileInfo.Extension;
                    }

                    item.Tag = fileInfo.FullName;
                    item.SubItems.Add(fileInfo.LastWriteTime.ToString());
                    item.SubItems.Add(fileInfo.Extension + "文件");
                    item.SubItems.Add(ShowFileSize(fileInfo.Length).Split('(')[0]);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            curFilePath = path;

            //tscboAddress.Text = curFilePath;

            toolStripStatusLabel1.Text = listView1.Items.Count + " 个项目";

            listView1.EndUpdate();
        }