- Joined
- Jul 26, 2011
- Messages
- 1
- Reaction score
- 0
hello there
I'm new to programming and i was writing a c program that would take in a directory as an argument and give me all the files of the directory. Here's the codes:
#include <stdio.h>
#include <string.h>
#include <dirent.h>
int main(int argc, char* argv[])
{
DIR* dir;
struct dirent* entry;
if (argc != 2 || !argv[1]){
printf ("please enter a path");
dir=opendir(argv[1]);
if (!dir) {
perror("opendir");
}
printf("Directory contents:\n");
while ( (entry = readdir(dir)) != NULL) {
printf("%s\n", entry->d_name);
}
}
}
I'm new to programming and i was writing a c program that would take in a directory as an argument and give me all the files of the directory. Here's the codes:
#include <stdio.h>
#include <string.h>
#include <dirent.h>
int main(int argc, char* argv[])
{
DIR* dir;
struct dirent* entry;
if (argc != 2 || !argv[1]){
printf ("please enter a path");
dir=opendir(argv[1]);
if (!dir) {
perror("opendir");
}
printf("Directory contents:\n");
while ( (entry = readdir(dir)) != NULL) {
printf("%s\n", entry->d_name);
}
}
}