Originally Posted by
cas
You're scalling stat() with filepathname each time, which is always /home/this/me/prog. Presumably you want to stat dentry->d_name instead (making sure you're in the correct directory, or building a path by combining filepathname and dentry->d_name).
That made a lot of since. Thanks for that insight. I was just wondering though with new fix I still get 512 printed out on some of the files. Is there a reason for this or did I not completely fix the problem.
Code:
struct stat statdata;
char filepath[256];
char *file;
static struct stat largestFiles[3];
int i = 0;
int x =0;
dentry = readdir(dpntr);
while(dentry != 0){
i=0;
if(strcmp((dentry->d_name),"..") > 0){
file = dentry->d_name;
printf("File name is: %s\n", file);
sprintf(filepath, "%s/%s",filepathname,file);
printf("FullPathName: %s \n", filepath);
if(!stat(filepath, &statdata)){
int size = statdata.st_size;
printf("Size of %s is %d\n\n\n ", file, size);
printout is
File name is: sqlnet.log
FullPathName: /home/it02/me/prog/sqlnet.log
Size of sqlnet.log is 4925
File name is: country.sql.txt
FullPathName: /home/it02/me/prog/country.sql.txt
Size of country.sql.txt is 23888
File name is: untitled folder
FullPathName: /home/it02/me/prog/untitled folder
Size of untitled folder is 512
that last file didn't seem to have anything in it but it returned 512 again