IE收藏夹里收藏的链接很多,查找也不方便,使用C编写一个小工具,可以将收藏夹里的链接文件生成到一个HTML文件上。

源码还有许多地方需要优化,后续我会优化,先分享出来。目的主要是为了练习C语言,这个代码中使用了最原始的C语言代码,比如结构体,指针,字符串操作,链表,目录遍历,读写文件等。

代码中一些地方原本是基于windows的C++写成,后来改成使用标准C函数。如果您和我一样,好多年不用C了,不防看看,重温当前学C的感觉。

请看官拍砖。

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. #include <iostream>
  6. #include <io.h>
  7. #include <direct.h>
  8. #include <string>
  9. #include <vector>
  10. #include <iomanip>
  11. #include <ctime>
  12.  
  13. using namespace std;
  14.  
  15. #define BUFLEN 1024
  16.  
  17. typedef struct UrlFile
  18. {
  19. char filename[200];
  20. char url[300];
  21. char path[300];
  22. char urltype[100];
  23. struct UrlFile *next;
  24. }UrlFileModel;
  25.  
  26. void getFiles( string path );
  27. char* getUrl(char* filename);
  28.  
  29. UrlFileModel Start;
  30. UrlFileModel *FileList;
  31.  
  32. int main()
  33. {
  34. FILE *file;
  35. int index=0;
  36. UrlFileModel *tmpnode;
  37.  
  38. Start.next=NULL;
  39. FileList=&Start;
  40.  
  41. getFiles( "C:\\Users\\ldy\\Favorites\\" );
  42.  
  43. tmpnode=&Start;
  44.  
  45. while(tmpnode)
  46. {
  47. char* url=getUrl(tmpnode->path);
  48.  
  49. if (url)
  50. {
  51. //printf("%s",url); //此处导致url字符串的截取
  52. strcpy(tmpnode->url,url);
  53. }
  54.  
  55. tmpnode=tmpnode-> next;
  56. }
  57.  
  58. if ((file=fopen("test.html","w"))==NULL) /*打开只写的文本文件*/
  59. {
  60. printf("cannot open file!");
  61. exit(0);
  62. }
  63.  
  64. tmpnode=&Start;
  65.  
  66. fputs("<html><head><title></title></head><body><table>",file);
  67.  
  68. while(tmpnode)
  69. {
  70. index++;
  71. printf( "%s\n ",tmpnode-> filename);
  72. //printf( "%s\n ",tmpnode->urltype);
  73.  
  74. fprintf(file,"<tr><td>%d</td><td><a href='%s' target='_blank'>%s</a></td><td>%s</td></tr>",index,tmpnode->url,tmpnode-> filename,tmpnode-> urltype);
  75.  
  76. tmpnode=tmpnode-> next;
  77. }
  78.  
  79. fputs("</table></body></html>",file);
  80. fclose(file); /*关文件*/
  81.  
  82. printf( "总计收藏的页面:%d\n ",index);
  83. fgetchar();
  84. }
  85.  
  86. void getFiles( string path )
  87. {
  88. //文件句柄
  89. long hFile = 0;
  90. //文件信息
  91. struct _finddata_t fileinfo;
  92.  
  93. string p;
  94. char urltype[]="fav";
  95.  
  96. if ((hFile = _findfirst(p.assign(path).append("\\*").c_str(),&fileinfo)) != -1)
  97. {
  98. do
  99. {
  100. //如果是目录,迭代之
  101. //如果不是,加入列表
  102. if ((fileinfo.attrib & _A_SUBDIR))
  103. {
  104.  
  105. if(strcmp(fileinfo.name,".") != 0 && strcmp(fileinfo.name,"..") != 0)
  106. getFiles( p.assign(path).append("\\").append(fileinfo.name) );
  107. }
  108. else
  109. {
  110.  
  111. FileList->next=(struct UrlFile*)malloc(sizeof(struct UrlFile));
  112. FileList=FileList->next;
  113. strcpy(FileList->filename,fileinfo.name);
  114. strcpy(FileList->urltype,path.c_str());
  115. strcpy(FileList->path,p.assign(path).append("\\").append(fileinfo.name).c_str());
  116.  
  117. FileList->next=NULL;
  118.  
  119. }
  120. } while(_findnext(hFile, &fileinfo) == 0);
  121.  
  122. _findclose(hFile);
  123.  
  124. }
  125.  
  126. }
  127.  
  128. char* getUrl(char* filename)
  129. {
  130. FILE *file;
  131. char buf[BUFLEN];
  132. int len=0,i=0;
  133.  
  134. char *delim = "BASEURL=";
  135.  
  136. char* tmpptr;
  137.  
  138. file=fopen(filename,"r");
  139. if (!file)
  140. {
  141. printf("file open error!");
  142. return NULL;
  143. }
  144.  
  145. while (fgets(buf,BUFLEN,file))
  146. {
  147. tmpptr=strstr(buf,"BASEURL=");
  148. if (!tmpptr)
  149. {
  150. continue;
  151. }
  152. int len=strlen(tmpptr);
  153. if (len>0)
  154. {
  155. tmpptr=strtok(tmpptr,"BASEURL=");
  156. printf("%s\n",tmpptr);
  157. break;
  158. }
  159. }
  160.  
  161. fclose(file);
  162. return tmpptr;
  163. }

使用C语言将IE收藏夹生成HTML的更多相关文章

  1. 基于Metronic的Bootstrap开发框架经验总结(12)--页面链接收藏夹功能的实现

    在一个系统里面,往往有很多菜单项目,每个菜单项对应一个页面,一般用户只需要用到一些常用的功能,如果每次都需要去各个层次的菜单里面去找对应的功能,那确实有点繁琐.特别是在菜单繁多,而客户又对系统整体不熟 ...

  2. paip.重装系统后firefox火狐收藏夹的恢复

    paip.重装系统后firefox火狐收藏夹的恢复 1.使用procmon跟踪ff保存收藏时候的读写文件.. D:\Users\attilax\AppData\Roaming\Mozilla\Fire ...

  3. Django Web开发【3】创建网络收藏夹

    这一节我们将继续一个创建网络收藏夹应用,并学习视图.模型以及模板的处理过程. Django是一个MVC开发框架,但是它的控制器对应的为view,而视图对应为模板(template),模型对应model ...

  4. 如何在地址栏(title标签里)和收藏夹里 加上网站的标志ICO、LOGO图片

    第一步:首先你必须要制作一个看起来既清楚又容易辨识的.ico格式的小图片. 我们将图标的大小定义为16x16 像素.此外在制作图形文件的时候,你可能需要把色盘设定成只使用标准的 16 色 Window ...

  5. js drag drop 收藏夹拖拽移除的简单例子

    代码 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title& ...

  6. 基于Metronic的Bootstrap开发框架经验总结(13)--页面链接收藏夹功能的实现2(利用Sortable进行拖动排序)

    在上篇随笔<基于Metronic的Bootstrap开发框架经验总结(12)--页面链接收藏夹功能的实现>上,我介绍了链接收藏夹功能的实现,以及对收藏记录的排序处理.该篇随笔主要使用功能按 ...

  7. 修复 Windows7 资源管理器左侧收藏夹无法展开问题

    相信大家在网上搜多到的解决办法大多数都是修改注册表,但是这个办法多数是无效的 1.运行regedit 2.展开到HKEY_CLASSES_ROOT\lnkfile 3.添加一个字符串值:IsShort ...

  8. JQUERY 实现加入收藏夹功能

    关于"加入收藏"的代码,很多人都不会重视,一般情况是随便在网上搜一个代码放在页面里就草草了事了.可是都没有做到主流浏览器的兼容.下面分享一段使用 jQuery 实现加入收藏夹的功能 ...

  9. 设为首页 添加到收藏夹 (share)

    设为首页,添加到收藏夹 分享自:http://my.oschina.net/lyx2012/blog/60036 设为首页 和 收藏本站js代码 兼容IE,chrome,ff <script t ...

随机推荐

  1. Nhiberate (三)测试

    (一)添加数据: public void AddUser(User user) { ISession session = NhibernateFactory.GetInstance().GetSess ...

  2. MVC模式--DropDownList数据绑定

    DropDownList数据绑定 在控制器中Controller中,为前台页面DropDownList准备的数据 List<bookInfo> bookList = bookManger. ...

  3. input上传按钮 文字修改办法

    解决思路是把input 放在文字的上边,弄成透明的,这样在点文字时,实际是点击了input,这样就实现了文件的上传. 具体代码: <style> #uploadImg{ font-size ...

  4. nginx限制访问速度

    转自:http://siwei.me/blog/posts/nginx-ip 参考:http://tengine.taobao.org/document_cn/http_limit_req_cn.ht ...

  5. bootstrap入门-1.可视化布局

    下载地址:http://v3.bootcss.com/getting-started/#download   HTML模板: <!DOCTYPE html> <html> &l ...

  6. 从Spring容器中获取Bean。ApplicationContextAware

    引言:我们从几个方面有逻辑的讲述如何从Spring容器中获取Bean.(新手勿喷) 1.我们的目的是什么? 2.方法是什么(可变的细节)? 3.方法的原理是什么(不变的本质)? 1.我们的目的是什么? ...

  7. 安装django

    我已经有Python3.5的环境了.我们去下载Django.https://github.com/django/django.git  直接下载为zip解压即可. 然后在命令提示符下安装 1.  切换 ...

  8. HttpContext.Current.Cache使用文件依赖问题

    HttpContext.Current.Cache.Insert("FCacheMs", tb, New CacheDependency(HttpContext.Current.S ...

  9. LeetCode----263. Ugly Number(Java)

    package isUgly263; /* * Write a program to check whether a given number is an ugly number. Ugly numb ...

  10. lua 操作中文字符串之截取和长度竖排显示

    前言 在游戏中,我们经常会遇到汉字的多行显示,比如名字竖行显示等.如下图: 为了实现上面的效果,lua实现分行是通过  \n  实现的,所以我们需要取出汉字,然后插入 \n 实现分行效果.还有一种就是 ...