I'm not sure if C can do this, but I'm hoping that I can make a program that will look into a directory, and print out all of the contents of the directory along with the file size of each file. As in I wanted it to look like this (possibly):

filename.txt -- 300 bytes

filename2.txt -- 400 bytes

filename3.txt -- 500 bytes

And so on.

So far, I created a program that can open a file, and it will print the bytes, but it does not read the entire directory, and I have to be specific with which file I want to read.. (which is not what I want).

Also You can use the fstat() system call which can fill in the struct stat for any file you want. From that stat you can access that file's size.
Please use the man pages to help you out. (Almost) Everything related to Linux is insanely well documented

Okay so this one worked out really great. I was able to list all the contents of the directory.. Now is there a way I can find the file size of each file that was listed and print it after the name? I've done this (it only listed the size of the first file): int main(){ DIR *dir; FILE *fp; struct dirent *ent; int size; if((dir = opendir("c:/")) != NULL){ while(fp = fopen("ex.txt", "rw")){ size = fileLength(fp); } while((ent = readdir (dir)) != NULL){ printf( "%s, size: %d\n", ent->d_name, size ); } closedir( dir ); } else{ perror( "" ); return -1; } }
–
chakolatemilkJan 28 '13 at 19:44