Hi there,
when it reaches i = 0 after it checks that the filename starts with 201,it is able to move the file but it stops working after a while.
when it reaches i = 0 after it checks that the filename starts with 201,it is able to move the file but it stops working after a while.
Code:
/*program to list all files in a directory*/
#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>
int main (void)
{
DIR *dp;
struct dirent *ep;
dp = opendir ("./");
char name[80];
if (dp != NULL)
{
while (ep = readdir (dp)){
char *s = ep->d_name;
puts(s);
int i = strncmp(s,"201",3);//compare up to the first two character
if(i == 0){
char cat[] = "../";
strcat(cat,s);
printf("%s\n",cat);
printf("%s\n",s);
rename(s,cat);
}
}
closedir (dp);
}
else perror ("Couldn't open the directory");
return 0;
}