#include<stdio.h>
#include<fcntl.h>
#include<dirent.h>
#include<string.h>
int openf(char *);
int main()
{
DIR *i;
struct dirent *k;
int j,l,s,flag=1,fd,fd1;
char *m = “txt.”;
char ch;
fd1 = openf(“new.txt”);
i = opendir(“./test”);
printf(“\n%d\n”,i);
while(( k = readdir(i)) != NULL)
{
flag=1;
l=strlen(k->d_name);
for(j = l-1,s=0;j >= l-4,s < 4 ;j–,s++ )
{
if((k->d_name[j])!= m[s])
{
flag=0;
goto q;
}
}
q: if(flag==1)
{
fd = openf(k->d_name);
while(read(fd, &ch, 1))
write(fd1,&ch,1);
close(fd);
}
}
printf(“\n”);
close(fd1);
}
int openf(char * s)
{
int fd;
fd = open(s,O_RDWR|O_CREAT,0666);
if(fd < 1)
perror(“open error”);
else
printf(“input file open succesfull fd = %d\n”,fd);
return fd;
}
Comments
Leave a comment