码迷,mamicode.com
首页 > 其他好文 > 详细

获取所有逻辑磁盘目录

时间:2019-01-09 19:27:09      阅读:202      评论:0      收藏:0      [点我收藏+]

标签:hand   [1]   etl   one   try   ati   images   ||   lower   

实现效果:

  技术分享图片

知识运用:

  Directory类的GetLogicalDrives方法    //检索计算机上的逻辑分区

  public static string[] GetLogicalDrives()

  GetDirectories方法    和GetFiles方法

实现代码:

        public void GetListViewItem(string path,ImageList imagelist,ListView lv)
        {
            lv.Items.Clear();
            SHFILEINFO shfi = new SHFILEINFO();
            try
            {
                string[] dirs = Directory.GetDirectories(path);
                string[] files = Directory.GetFiles(path);
                for (int i = 0; i < dirs.Length; i++)
                { 
                    string[] info=new string[4];
                    DirectoryInfo dir = new DirectoryInfo(dirs[i]);
                    if (!(dir.Name == "RECYCLER" || dir.Name == "RECYCLED" ||
                        dir.Name == "Recycled" ||dir.Name == "System Volume Information"))
                    { 
                        SHGetFileInfo(dirs[i], 
                                    (uint)0x80, ref shfi, 
                                    (uint)System.Runtime.InteropServices.Marshal.SizeOf(shfi),
                                    (uint)(0x100 | 0x400));
                        imagelist.Images.Add(dir.Name,(Icon)Icon.FromHandle(shfi.hIcon).Clone());
                        info[0] = dir.Name;
                        info[1] = "";
                        info[2] = "文件夹";
                        info[3] = dir.LastAccessTime.ToString();
                        ListViewItem item = new ListViewItem(info,dir.Name);
                        lv.Items.Add(item);
                    }
                }
                for (int i = 0; i < files.Length; i++)
                {
                    string[] info = new string[4];
                    FileInfo fi = new FileInfo(files[i]);
                    string Newtype=fi.Extension.ToLower();
                    if (!(Newtype == "sys" || Newtype == "ini" || Newtype == "bin" ||
                            Newtype == "log" || Newtype == "com" || Newtype == "bat" || Newtype == "db"))
                    {
                        SHGetFileInfo(files[i],
                                    (uint)0x80, ref shfi,
                                    (uint)System.Runtime.InteropServices.Marshal.SizeOf(shfi),
                                    (uint)(0x100 | 0x400));
                        imagelist.Images.Add(fi.Name,(Icon)Icon.FromHandle(shfi.hIcon));
                        info[0] = fi.Name;
                        info[1] = fi.Length.ToString();
                        info[2] = fi.Extension.ToString();
                        info[3] = fi.LastAccessTime.ToString();
                        ListViewItem item = new ListViewItem(info,fi.Name);
                        lv.Items.Add(item);
                    }
                }
            }
            catch {}
        }

  

获取所有逻辑磁盘目录

标签:hand   [1]   etl   one   try   ati   images   ||   lower   

原文地址:https://www.cnblogs.com/feiyucha/p/10246313.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!