生成文件列表并读取列表中各个文件的指定内容(C语言)
2016-12-13 10:27
309 查看
记录C语言学习经历
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void readFile(char* strInput,char* strOuput)
{
FILE* fp = fopen(strInput, "r");
printf("当前读取文件名:%s\n",strInput);
FILE* fp2 = fopen(strOuput, "a");
if (!fp)
{
puts("文件读取时打开失败!");
return ;
}
if (!fp2)
{
puts("文件写入时打开失败!");
return ;
}
char buf[256] = {0};
char* p;
while (1)
{
if (NULL == fgets(buf, 256, fp))
return;
if (p = strstr(buf, "Unc."))//匹配字符串
{
fprintf(fp2, "%.60s\n", p);
}
}
fclose(fp);
fclose(fp2);
}
int main()
{
system("dir D:\\file\\abc*.txt /B > D:\\file\\gdl.txt");//生成文件名列表
FILE* pf = fopen("D:\\file\\gdl.txt","r");
char buf[64];
int len;//截断字符串
int i = 0;
while(fgets(buf, 64, pf))
{
char tmp[32] = {0};
sprintf(tmp,"%s%s","D:\\\\file\\\\",buf);//拼接
len = strlen(tmp);
tmp[len - 1] = '\0';
readFile(tmp,"D:\\file\\a.txt");
++i;
}
printf("读取了%d个文件的数据!",i);
fclose(pf);
system("pause");
return 0;
}
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void readFile(char* strInput,char* strOuput)
{
FILE* fp = fopen(strInput, "r");
printf("当前读取文件名:%s\n",strInput);
FILE* fp2 = fopen(strOuput, "a");
if (!fp)
{
puts("文件读取时打开失败!");
return ;
}
if (!fp2)
{
puts("文件写入时打开失败!");
return ;
}
char buf[256] = {0};
char* p;
while (1)
{
if (NULL == fgets(buf, 256, fp))
return;
if (p = strstr(buf, "Unc."))//匹配字符串
{
fprintf(fp2, "%.60s\n", p);
}
}
fclose(fp);
fclose(fp2);
}
int main()
{
system("dir D:\\file\\abc*.txt /B > D:\\file\\gdl.txt");//生成文件名列表
FILE* pf = fopen("D:\\file\\gdl.txt","r");
char buf[64];
int len;//截断字符串
int i = 0;
while(fgets(buf, 64, pf))
{
char tmp[32] = {0};
sprintf(tmp,"%s%s","D:\\\\file\\\\",buf);//拼接
len = strlen(tmp);
tmp[len - 1] = '\0';
readFile(tmp,"D:\\file\\a.txt");
++i;
}
printf("读取了%d个文件的数据!",i);
fclose(pf);
system("pause");
return 0;
}
相关文章推荐
- 使用Python将TXT文本内容读取后生成指定XML格式的文件
- 使用Python将TXT文本内容读取后生成指定XML格式的文件
- c语言:读取文件中的指定内容
- 读取指定URL连接的文件内容
- [ASP] 使用asp读取指定文件夹的文件列表(返回xml)
- python读取指定字节及位置的文件内容
- 将指定的asp文件内容生成HTML文件
- C语言读取文件内容统计代码
- 读取指定路径的文件及子文件夹列表
- 将指定的asp文件内容生成HTML文件
- 文件的指定位置读取内容
- VC逐行读取指定文件的内容
- C#生成PDF文档,读取TXT文件内容
- 将指定的asp文件内容生成HTML文件
- [VB.NET]vb.net如何读取数据库生成指定格式的xml文件
- Java读取指定文件的内容
- C#生成PDF文档,读取TXT文件内容
- 通过NSInputStream读取大文件的指定起始内容
- asp把指定网址的内容生成为PDF文件ABCPDF asp 生成pdf
- iphone存储以及读取指定文件(Documents)中的内容