• C# 获取收藏夹中所有网址代码


    //收藏夹太多太混乱,打算系统整理合并.整个工具未开发完成

    //下面是读取系统默认收藏夹文件中所有包含子目录中的链接网址信息代码

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.IO;

    namespace FavoriteManager
    {
        public partial class Form2 : Form
        {
            public Form2()
            {
                InitializeComponent();
            }

            private void Form2_Load(object sender, EventArgs e)
            {
                string FavoritePath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Favorites);
                LoadLinkFolders(new System.IO.DirectoryInfo(FavoritePath));
            }
            /// <summary>
            /// 遍历系统收藏夹目录中所有链接网址
            /// </summary>
            /// <param name="ParentFolder"></param>
            private void LoadLinkFolders(DirectoryInfo ParentFolder)
            {
                string ParentFolderName = ParentFolder.Name;

                foreach (FileInfo SubFile in ParentFolder.GetFiles())
                {
                    string strCurrentLinkUrl = GetLinkFileUrl(SubFile.FullName);
                    Console.WriteLine("当前文件" + SubFile.FullName + "链接网址为" + strCurrentLinkUrl);

                }
                foreach (DirectoryInfo SubFolder in ParentFolder.GetDirectories())
                {
                    try
                    {
                        LoadLinkFolders(SubFolder);
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("读取当前文件夹" + SubFolder.FullName + "收藏网址失败!");

                    }
                }
            }
            /// <summary>
            /// 根据收藏夹URL文件获取对应的链接网址
            /// </summary>
            /// <param name="linkFilePath"></param>
            /// <returns></returns>
            private string GetLinkFileUrl(string linkFilePath)
            {
                string strReturn = "";
                //异常检测开始
                try
                {
                    FileStream fs = new FileStream(linkFilePath, FileMode.Open, FileAccess.Read);//读取文件设定
                    StreamReader myStreamReader = new StreamReader(fs, System.Text.Encoding.Default);//设定读写的编码
                    //使用StreamReader类来读取文件
                    myStreamReader.BaseStream.Seek(0, SeekOrigin.Begin);
                    string strLine = myStreamReader.ReadLine();
                    while (strLine != null)
                    {
                        if (strLine.IndexOf("URL=") == 0)
                        {
                            strReturn = strLine.Replace("URL=", "");
                            break;
                        }
                        strLine = myStreamReader.ReadLine();
                    }
                    //关闭此StreamReader对象
                    myStreamReader.Close();
                }
                catch
                {
                    strReturn = "";
                }
                return strReturn;
            }
        }
    }

  • 相关阅读:
    Junit单元测试学习笔记(一)
    perl 函数参数传递与返回值(一)
    Oracle blob字段类型 文件读写实例
    测试沙龙的一些感悟
    常用排序算法选择排序
    perl 哈希(hash)学习笔记(一)
    perl 自定义包/模块的使用(正则表达式匹配email地址和ip)
    常用排序算法冒泡排序
    如何使用excel计算工龄
    畅想(3)打通编程的任督二脉 人工智能
  • 原文地址:https://www.cnblogs.com/xqf222/p/3306817.html
Copyright © 2020-2023  润新知