|
楼主 |
发表于 2004-9-10 11:01:31
|
显示全部楼层
[quote:2a47590be3="mozilla"]没事干给你写了一段c
[code:1]
#include <stdio.h>
#include <dirent.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
char *key[]=
{"g_Tel","g_Sex","g_Year","g_Month","g_Day","g_Address",
"g_Mail","g_Serial","g_Account","g_Password"
};
int main(int argc,char **argv)
{
DIR *mdir;
struct dirent *ent;
struct stat st;
int i,j;
FILE *fp;
char line[128];
char filename[FILENAME_MAX];
mdir=opendir(argv[1]);
if(!mdir)
return 0;
while(ent=readdir(mdir))
{
sprintf(filename,"%s/%s",argv[1],ent->d_name);
lstat(filename,&st);
if(!S_ISREG(st.st_mode))
continue;
fp=fopen(filename,"r");
if(!fp)
continue;
while(fgets(line,128,fp) != NULL)
{
for(i=strlen(line);i>0;i--)
{
if(line[i-1] == '\n')
{
line[i-1]='\0';
break;
}
}
for(i=0;i<10;i++)
{
if(strncmp(line,key[i],strlen(key[i])) == 0)
{
j=strlen(key[i])+1;
for(;j<strlen(line);j++)
{
if(line[j] != ' ')
break;
}
if(i<9)
printf("%s|",line+j);
else
printf("%s\n",line+j);
}
}
}
fclose(fp);
}
closedir(mdir);
}
[/code:1][/quote]
是一个文件夹里有N多.o文件
譬如说目录/83里有好几十万个.o文件 要把它合并成一个文挡(执行结果) |
|