• 获取所有逻辑磁盘目录


    实现效果:

      

    知识运用:

      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 {}
            }
    

      

  • 相关阅读:
    堆排序算法
    二叉树的创建、遍历(递归和非递归实现)、交换左右子数、求高度(c++实现)
    hdoj1010 奇偶剪枝+DFS
    常见排序算法c++总结
    B
    C
    D
    E
    G
    F
  • 原文地址:https://www.cnblogs.com/feiyucha/p/10246313.html
Copyright © 2020-2023  润新知