Have you looked in the manual to see if you can find some of the parts yiou'll need, like [man]readdir[/man] to read a directory? The manual comes with example code for just about all of it. If you've never used loops before, consider this a chance to study and learn.
No, we're not going to write your code for you.