用c对文件指定内容进行扫描提取特定内容 求帮忙

荔鸷 2020-11-20 11:47:56
众所周知软件大多会有一个缓存目录,现在需要一个程序能够去读取其他文件的内容,并提取需要的特定信息存储到相应的缓存目录下(主线),因为不知道那个装有特定内容的文件在哪,所以需要对目录和文件进行扫描(支线) 额外信息: 需要提取的内容为:out put words 据说要扫描的文件名为:TheFile
...全文
158 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
荔鸷 2020-11-25
  • 打赏
  • 举报
回复
引用 6 楼 ctrigger的回复:
[quote=引用 5 楼 yxj3515001663 的回复:][quote=引用 4 楼 ctrigger的回复:][quote=引用 3 楼 yxj3515001663 的回复:]我有个问题,为什么我c语言打程序的时候声明结构体struct dirent里面没有d_type啊


man文档中的定义:
struct dirent {
ino_t d_ino; /* inode number */
off_t d_off; /* offset to the next dirent */
unsigned short d_reclen; /* length of this record */
unsigned char d_type; /* type of file; not supported
by all file system types */
char d_name[256]; /* filename */
};
[/quote]
这不是系统定义的结构体吗[/quote]

d_type 注释中,就是有些文件系统不支持。我的windows和fedora系统都有。[/quote] 要是不支持的话就用不了吗?还是说可以定义使用
荔鸷 2020-11-25
  • 打赏
  • 举报
回复
引用 6 楼 ctrigger的回复:
[quote=引用 5 楼 yxj3515001663 的回复:][quote=引用 4 楼 ctrigger的回复:][quote=引用 3 楼 yxj3515001663 的回复:]我有个问题,为什么我c语言打程序的时候声明结构体struct dirent里面没有d_type啊


man文档中的定义:
struct dirent {
ino_t d_ino; /* inode number */
off_t d_off; /* offset to the next dirent */
unsigned short d_reclen; /* length of this record */
unsigned char d_type; /* type of file; not supported
by all file system types */
char d_name[256]; /* filename */
};
[/quote]
这不是系统定义的结构体吗[/quote]

d_type 注释中,就是有些文件系统不支持。我的windows和fedora系统都有。[/quote] 不支持的话就没办法使用了吗
ctrigger 2020-11-24
  • 打赏
  • 举报
回复
引用 5 楼 yxj3515001663 的回复:
[quote=引用 4 楼 ctrigger的回复:][quote=引用 3 楼 yxj3515001663 的回复:]我有个问题,为什么我c语言打程序的时候声明结构体struct dirent里面没有d_type啊


man文档中的定义:
struct dirent {
ino_t d_ino; /* inode number */
off_t d_off; /* offset to the next dirent */
unsigned short d_reclen; /* length of this record */
unsigned char d_type; /* type of file; not supported
by all file system types */
char d_name[256]; /* filename */
};
[/quote]
这不是系统定义的结构体吗[/quote]

d_type 注释中,就是有些文件系统不支持。我的windows和fedora系统都有。
荔鸷 2020-11-24
  • 打赏
  • 举报
回复
引用 4 楼 ctrigger的回复:
[quote=引用 3 楼 yxj3515001663 的回复:]我有个问题,为什么我c语言打程序的时候声明结构体struct dirent里面没有d_type啊


man文档中的定义:
struct dirent {
ino_t d_ino; /* inode number */
off_t d_off; /* offset to the next dirent */
unsigned short d_reclen; /* length of this record */
unsigned char d_type; /* type of file; not supported
by all file system types */
char d_name[256]; /* filename */
};
[/quote] 这不是系统定义的结构体吗
ctrigger 2020-11-24
  • 打赏
  • 举报
回复
引用 3 楼 yxj3515001663 的回复:
我有个问题,为什么我c语言打程序的时候声明结构体struct dirent里面没有d_type啊


man文档中的定义:
struct dirent {
ino_t d_ino; /* inode number */
off_t d_off; /* offset to the next dirent */
unsigned short d_reclen; /* length of this record */
unsigned char d_type; /* type of file; not supported
by all file system types */
char d_name[256]; /* filename */
};
荔鸷 2020-11-24
  • 打赏
  • 举报
回复
引用 2 楼 ctrigger的回复:
解决思路,仅供参考:
1. opendir
2. 循环readdir
a. 普通文件,比较文件名,扫描指定字符串 strstr函数。
c. 其他类型文件,忽略,continue。
b. 目录,递归opendir。
3. 结束
我有个问题,为什么我c语言打程序的时候声明结构体struct dirent里面没有d_type啊
ctrigger 2020-11-21
  • 打赏
  • 举报
回复
解决思路,仅供参考:
1. opendir
2. 循环readdir
a. 普通文件,比较文件名,扫描指定字符串 strstr函数。
c. 其他类型文件,忽略,continue。
b. 目录,递归opendir。
3. 结束
an_bachelor 2020-11-21
  • 打赏
  • 举报
回复
首先要确定能访问这个文件,如果文件被程序互斥性打开,那后来的程序是打不开这个文件的。

70,037

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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