C如何获取某文件中某一类型文件,且对其排列

nohack315 2011-07-05 05:28:56
比如某文件下有些文件我用日期加时间命名的文件
20110705171011123.c
20110705171112123.c
20110705171214122.c 。。。

我现在想对其统计总数,取年月日时分罗列出来,且附带大小(kb)


total = n;

序列号 时间 大小
1 201107051710 1
2 201107051712 2
3 201107051714 5
... ...
...全文
69 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
nohack315 2011-07-06
  • 打赏
  • 举报
回复
谢谢
自己整了个, 你们的方法我在去看看

#include <stdio.h>
#include <string.h>
#include <dirent.h>
#define MAX 89
int selectfile(const struct dirent *drt)
{
if(strstr(drt->d_name, ".c") != NULL)
return 1;
else
return 0;
}
main()
{
struct dirent **namelist;
int i, total;
char buff[MAX][13]={0};

total = scandir("./scandir",&namelist, selectfile, alphasort);
printf("total = %d\n", total);
if (total < 0)
{
printf("scandir error: %d\r\n", total);
return 0;
}
for (i = 0; i < total; i++)
strncpy(buff[i],namelist[i]->d_name,12);
// buff[13] = '\0';
for(i = 0; i < total; i++)
printf("%d %s\n", i, buff[i]);
//printf("%d*%s\n",i ,namelist[i]->d_name);
}
yong_f 2011-07-06
  • 打赏
  • 举报
回复
用目录操作函数pendir,readdir
文件操作函数open,close,stat等。
nohack315 2011-07-06
  • 打赏
  • 举报
回复
是 linux 下的
nohack315 2011-07-06
  • 打赏
  • 举报
回复
不是取的文件名 我还要将文件名处理 比如20110705171512123 -》201107051715
能给出实现的例子么
t_presley 2011-07-05
  • 打赏
  • 举报
回复
如果是linux平台下,有一套目录操作函数,opendir,readdir等等
nohack315 2011-07-05
  • 打赏
  • 举报
回复
C下的 我想把这些文件列表 实现选取好打开
challenge99 2011-07-05
  • 打赏
  • 举报
回复
平台?
justkk 2011-07-05
  • 打赏
  • 举报
回复
fopen
fgets
lstat
fclose

23,120

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧