Ejemplo n.º 1
0
        /// <summary>
        /// 根据DirectoryInfo数组更新控件listbox
        /// </summary>
        /// <param name="lb"></param>
        /// <param name="dir"></param>
        public static void UpdateByDirectoryInfos(ListBox lb, DirectoryInfo dir)
        {
            lb.BeginInit();
            var it = new MyListBoxItem(dir.Name, MyIcons.folder);

            it.MyMessage = "目录路径:" + dir.FullName;
            lb.Items.Add(it);
            lb.EndInit();
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 根据FileInfo数组更新控件listbox
 /// </summary>
 /// <param name="lb"></param>
 /// <param name="files"></param>
 public static void UpdateByFileInfos(ListBox lb, FileInfo[] files)
 {
     lb.BeginInit();
     foreach (var i in files)
     {
         var it = new MyListBoxItem(i.Name, MyIcons.file);
         it.MyMessage = "所在路径:" + i.DirectoryName;
         lb.Items.Add(it);
     }
     lb.EndInit();
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 根据指定路径返回listboxItem集合
        /// </summary>
        /// <param name="path">指定路径</param>
        /// <returns>listboxItem集合</returns>
        public static List <MyListBoxItem> CreatLBItemFromPath(string path)
        {
            List <MyListBoxItem> res = new List <MyListBoxItem>();

            if (path == "")
            {
                DriveInfo[] disksInfo = DriveInfo.GetDrives();
                int         j         = 0;
                foreach (var i in disksInfo)
                {
                    MyListBoxItem lbit = new MyListBoxItem(
                        disksInfo[j].VolumeLabel + " (" + i.Name.Substring(0, 2) + ")", MyIcons.disk);
                    lbit.MyMessage = "可用空间:" + (disksInfo[j].TotalFreeSpace / 1024 / 1024 / 1024).ToString() + "GB"
                                     + "\n总大小:" + (disksInfo[j].TotalSize / 1024 / 1024 / 1024).ToString() + "GB";
                    res.Add(lbit);
                    j++;
                }
                return(res);
            }
            DirectoryInfo _files = new DirectoryInfo(path);

            FileInfo[]      files = _files.GetFiles("*", SearchOption.TopDirectoryOnly);
            DirectoryInfo[] dirs  = _files.GetDirectories("*", SearchOption.TopDirectoryOnly);
            foreach (var i in files)
            {
                if ((i.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
                {
                    continue;
                }
                MyListBoxItem lbit = new MyListBoxItem(i.Name, MyIcons.file);
                lbit.MyMessage = i.Name + "\n类型:" + i.Extension + "文件\n修改日期:" + i.LastWriteTime.ToString();
                res.Add(lbit);
            }
            foreach (var i in dirs)
            {
                if ((i.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
                {
                    continue;
                }
                MyListBoxItem lbit = new MyListBoxItem(i.Name, MyIcons.folder);
                lbit.MyMessage = i.Name + "\n创建日期:" + i.CreationTime;
                res.Add(lbit);
            }
            return(res);
        }