int ansibackup(char * directory, DIR * dpntry) { struct dirent *dentry; mode_t perms = 0700; //As the loop progresses the bakdir (for some strange reason) keeps being appended //the stuff that should be appended to filepathname array. // char bakdir[strlen(directory)]; strcpy(bakdir,directory); dentry = readdir (dpntry); while (dentry != 0) { struct stat statdata; char filepathname[256]; //resets every loop iteration right? sprintf(filepathname, "%s/%s", directory, dentry->d_name);//I concat new stuff to filepathname printf("Looking at %s/%s\n", directory,dentry->d_name); dentry = readdir( dpntry); } return 1; }