frmNeatenFavorites.cs
上传用户:hxjiliang
上传日期:2022-04-23
资源大小:182k
文件大小:3k
源码类别:

浏览器

开发平台:

C#

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using IWshRuntimeLibrary;
  9. using System.IO;
  10. namespace MyWebIE
  11. {
  12.     public partial class frmNeatenFavorites : Form
  13.     {
  14.         public frmNeatenFavorites()
  15.         {
  16.             InitializeComponent();
  17.         }
  18.         /// <summary>
  19.         /// 获取收藏夹所有的文件
  20.         /// </summary>
  21.         /// <param name="Dpath"></param>
  22.         private void scan(string Dpath)
  23.         {
  24.             DirectoryInfo DInfo = new DirectoryInfo(Dpath);
  25.             FileSystemInfo[] FSInfo = DInfo.GetFiles();
  26.             for (int i = 0; i < FSInfo.Length; i++)
  27.             {
  28.                 listBox1.Items.Add(FSInfo[i].ToString());
  29.             }
  30.         }
  31.         /// <summary>
  32.         /// 删除指定的收藏文件
  33.         /// </summary>
  34.         /// <param name="sender"></param>
  35.         /// <param name="e"></param>
  36.         private void button4_Click(object sender, EventArgs e)
  37.         {
  38.             if (listBox1.SelectedItems.Count == 0)             //判断是否选择项目
  39.             { }
  40.             else
  41.             {
  42.                 //获取选择项的路径
  43.                 string Path = path + "\" + listBox1.SelectedItem.ToString();
  44.                 //获取选择项目的扩展名
  45.                 string Stype = Path.Substring(Path.LastIndexOf(".") + 1);
  46.                 if (Stype == "url")                             //如果扩展名为“url”
  47.                 {
  48.                     FileInfo info = new FileInfo(Path);         //根据选择项的路径实例化FileInfo
  49.                     info.Delete();                              //然后调用FileInfo类的Delete方法进行删除  
  50.                     listBox1.Items.Clear();                     //清空ListBox控件的项目
  51.                     scan(path);                                 //重新遍历收藏夹
  52.                 }
  53.                 else
  54.                 { }
  55.             }
  56.         }
  57.         /// <summary>
  58.         /// 关闭
  59.         /// </summary>
  60.         /// <param name="sender"></param>
  61.         /// <param name="e"></param>
  62.         private void button1_Click(object sender, EventArgs e)
  63.         {
  64.             this.Close();
  65.         }
  66.         /// <summary>
  67.         /// 获取收藏夹路径
  68.         /// </summary>
  69.         public string path = Environment.GetFolderPath(Environment.SpecialFolder.Favorites);
  70.         private void frmNeatenFavorites_Load(object sender, EventArgs e)
  71.         {
  72.             scan(path);
  73.         }
  74.     }
  75. }