Example #1
0
 //--------------------各种函数------------------------------------------------------
 void CreatDir()
 {
     try
     {
         if (cPath == @"我的电脑")
         {
             MessageBox.Show("无法新建文件夹!");
             return;
         }
         string path    = Path.Combine(cPath, "新建文件夹");
         int    i       = 1;
         string newPath = path;
         while (Directory.Exists(newPath))
         {
             newPath = path + i;
             i++;
         }
         Directory.CreateDirectory(newPath);
         DirectoryInfo dir     = new DirectoryInfo(newPath);
         ListViewItem  dirItem = listView1.Items.Add("新建文件夹" + (i - 1 == 0 ? "" : (i - 1).ToString()));
         dirItem.SubItems.Add("新建文件夹" + (i - 1 == 0 ? "" : (i - 1).ToString()));
         Icon dirIcon = GetSystemIcon.GetDirectoryIcon();
         imageList2.Images.Add(dir.Name, dirIcon);
         dirItem.ImageKey = dir.Name;
         dirItem.Name     = dir.FullName;
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Example #2
0
        void LoadDrivers()
        {
            listView1.Clear();
            TreeNode NodeDir = new TreeNode("我的电脑", 3, 3);

            treeView1.Nodes.Add(NodeDir);
            DriveInfo[] drives = DriveInfo.GetDrives();
            cPath = "我的电脑";
            toolStripComboBox1.Text = cPath;
            foreach (DriveInfo drive in drives)
            {
                ListViewItem item = listView1.Items.Add(drive.Name);
                if (drive.DriveType == DriveType.CDRom)
                {
                    item.Name = drive.Name;
                    TreeNode objNode = new TreeNode(drive.Name, 2, 2);
                    NodeDir.Nodes.Add(objNode);
                    Icon drvIcon = GetSystemIcon.GetIconByFileName(drive.Name);
                    imageList2.Images.Add(drive.Name, drvIcon);
                    imageList3.Images.Add(drive.Name, drvIcon);
                    item.ImageKey = drive.Name;
                }
                else if (drive.DriveType == DriveType.Fixed)
                {
                    item.Name = drive.Name;
                    TreeNode objNode = new TreeNode(drive.Name, 1, 1);
                    NodeDir.Nodes.Add(objNode);
                    Icon drvIcon = GetSystemIcon.GetIconByFileName("c:\\");
                    imageList2.Images.Add(drive.Name, drvIcon);
                    imageList3.Images.Add(drive.Name, drvIcon);
                    item.ImageKey = drive.Name;
                }
                else if (drive.DriveType == DriveType.Removable)
                {
                    item.Name = drive.Name;
                    TreeNode objNode = new TreeNode(drive.Name, 4, 4);
                    NodeDir.Nodes.Add(objNode);
                    Icon drvIcon = GetSystemIcon.GetIconByFileName(drive.Name);
                    imageList2.Images.Add(drive.Name, drvIcon);
                    imageList3.Images.Add(drive.Name, drvIcon);
                    item.ImageKey = drive.Name;
                }
                item.SubItems.Add("");
                item.SubItems.Add("驱动");
                item.SubItems.Add("");
                this.listView1.Columns.Add("名称", this.listView1.Width / 4, HorizontalAlignment.Center);
                this.listView1.Columns.Add("大小", this.listView1.Width / 4, HorizontalAlignment.Center);
                this.listView1.Columns.Add("类型", this.listView1.Width / 4, HorizontalAlignment.Center);
                this.listView1.Columns.Add("修改时间", this.listView1.Width / 4, HorizontalAlignment.Center);
                imageList2.ColorDepth = ColorDepth.Depth32Bit;
            }
        }
Example #3
0
 void ListShow(string path)
 {
     listView1.Items.Clear();
     try
     {
         DirectoryInfo   currentDir = new DirectoryInfo(path);
         DirectoryInfo[] dirs       = currentDir.GetDirectories();
         FileInfo[]      files      = currentDir.GetFiles();
         foreach (DirectoryInfo dir in dirs)
         {
             ListViewItem dirItem = listView1.Items.Add(dir.Name);
             Icon         dirIcon = GetSystemIcon.GetDirectoryIcon();
             imageList2.Images.Add(dir.Name, dirIcon);
             imageList3.Images.Add(dir.Name, dirIcon);
             dirItem.SubItems.Add("");
             dirItem.SubItems.Add("文件夹");
             dirItem.SubItems.Add(dir.LastAccessTimeUtc.ToString());
             dirItem.ImageKey = dir.Name;
             dirItem.Name     = dir.FullName;
         }
         foreach (FileInfo file in files)
         {
             ListViewItem fileItem = listView1.Items.Add(file.Name);
             Icon         fileIcon = GetSystemIcon.GetIconByFileName(file.FullName);
             imageList2.Images.Add(file.Name, fileIcon);
             imageList3.Images.Add(file.Name, fileIcon);
             fileItem.SubItems.Add(file.Length.ToString() + "字节");
             fileItem.SubItems.Add(file.Extension);
             fileItem.SubItems.Add(file.LastWriteTimeUtc.ToString());
             fileItem.ImageKey = file.Name;
             fileItem.Name     = file.FullName;
         }
         this.listView1.Columns.Add("名称", this.listView1.Width / 4, HorizontalAlignment.Center);
         this.listView1.Columns.Add("大小", this.listView1.Width / 4, HorizontalAlignment.Center);
         this.listView1.Columns.Add("类型", this.listView1.Width / 4, HorizontalAlignment.Center);
         this.listView1.Columns.Add("修改时间", this.listView1.Width / 4, HorizontalAlignment.Center);
         imageList2.ColorDepth = ColorDepth.Depth32Bit;
         cPath = path;
         toolStripComboBox1.Text    = cPath;
         toolStripStatusLabel1.Text = listView1.Items.Count + "个对象";
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Example #4
0
 void ListDrive()
 {
     listView1.Clear();
     DriveInfo[] drives = DriveInfo.GetDrives();
     foreach (DriveInfo drive in drives)
     {
         ListViewItem item = listView1.Items.Add(drive.Name);
         if (drive.DriveType == DriveType.CDRom)
         {
             item.Name = drive.Name;
             Icon drvIcon = GetSystemIcon.GetIconByFileName(drive.Name);
             imageList2.Images.Add(item.Name, drvIcon);
             imageList3.Images.Add(item.Name, drvIcon);
             item.ImageKey = drive.Name;
         }
         else if (drive.DriveType == DriveType.Fixed)
         {
             item.Name = drive.Name;
             Icon drvIcon = GetSystemIcon.GetIconByFileName("c:\\");
             imageList2.Images.Add(item.Name, drvIcon);
             imageList3.Images.Add(item.Name, drvIcon);
             item.ImageKey = drive.Name;
         }
         else if (drive.DriveType == DriveType.Removable)
         {
             item.Name = drive.Name;
             Icon drvIcon = GetSystemIcon.GetIconByFileName(drive.Name);
             imageList2.Images.Add(item.Name, drvIcon);
             imageList3.Images.Add(item.Name, drvIcon);
             item.ImageKey = drive.Name;
         }
         item.SubItems.Add("");
         item.SubItems.Add("驱动");
         item.SubItems.Add("");
         imageList2.ColorDepth = ColorDepth.Depth32Bit;
     }
     this.listView1.Columns.Add("名称", this.listView1.Width / 4, HorizontalAlignment.Center);
     this.listView1.Columns.Add("大小", this.listView1.Width / 4, HorizontalAlignment.Center);
     this.listView1.Columns.Add("类型", this.listView1.Width / 4, HorizontalAlignment.Center);
     this.listView1.Columns.Add("修改时间", this.listView1.Width / 4, HorizontalAlignment.Center);
     cPath = "我的电脑";
     toolStripComboBox1.Text    = cPath;
     toolStripStatusLabel1.Text = listView1.Items.Count + "个对象";
 }