免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12
最近访问板块 发新帖
楼主: landker
打印 上一主题 下一主题

[C] ls的问题 [复制链接]

论坛徽章:
12
子鼠
日期:2014-10-11 16:46:482016科比退役纪念章
日期:2018-03-16 10:24:0515-16赛季CBA联赛之山东
日期:2017-11-10 14:32:142016科比退役纪念章
日期:2017-09-02 15:42:4715-16赛季CBA联赛之佛山
日期:2017-08-28 17:11:5515-16赛季CBA联赛之浙江
日期:2017-08-24 16:55:1715-16赛季CBA联赛之青岛
日期:2017-08-17 19:55:2415-16赛季CBA联赛之天津
日期:2017-06-29 10:34:4315-16赛季CBA联赛之四川
日期:2017-05-16 16:38:55黑曼巴
日期:2016-07-19 15:03:112015亚冠之萨济拖拉机
日期:2015-05-22 11:38:5315-16赛季CBA联赛之北京
日期:2019-08-13 17:30:53
11 [报告]
发表于 2017-06-24 23:04 |只看该作者
在windows,很久之前写的了,MinGW

g++  treeT.cpp -municode -D_UNICODE -o treeT_UNI

or

g++  treeT.cpp -o treeT_ASC


  1. #include <iostream>
  2. #include <cstdio>
  3. #include <fcntl.h>
  4. #include <sys/stat.h>
  5. #include <dirent.h>
  6. #include <cwchar>
  7. #include <sys/types.h>
  8. #include <sys/stat.h>
  9. #include <cstring>

  10. #define NAME_MAX 1024

  11. void func(wchar_t path[]);
  12. static FILE * fp = _wfopen(L"tree_.txt", L"wb");

  13. int wmain(int argc, wchar_t *argv[] )
  14. {
  15.     wchar_t pth[] = L"D:\\Extra";
  16.     func(pth);
  17.     fclose(fp);
  18.     return 0;
  19. }

  20. void func(wchar_t path[])
  21. {
  22.     _WDIR * a = _wopendir(path);
  23.     _wdirent * dp;
  24.     _WDIR * aa;
  25.     struct stat stbuf;

  26.     wchar_t fullpath[NAME_MAX] = L"";

  27.     while (dp = _wreaddir(a))
  28.     {
  29.         if (
  30.                wcscmp(dp->d_name, L".") == 0
  31.             || wcscmp(dp->d_name, L"..") == 0  
  32.         )
  33.         {
  34.             continue;
  35.         }

  36.         swprintf(fullpath, L"%ls\\%ls", path, dp->d_name);
  37.         wstat(fullpath, &stbuf);

  38.         if ( (stbuf.st_mode & S_IFMT) == S_IFDIR )
  39.         {
  40.             func( fullpath );
  41.         }
  42.         else
  43.         {
  44.             //output file list
  45.             fwprintf(stderr, L"%ld\t%ls\r\n",  stbuf.st_mtime, fullpath );
  46.         }

  47.     }
  48.     _wclosedir(a);
  49.    
  50. }

复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP