Skip to content

Instantly share code, notes, and snippets.

@huseyin
Last active August 29, 2015 14:18
Show Gist options
  • Save huseyin/ece853d0983c1ee59370 to your computer and use it in GitHub Desktop.
Save huseyin/ece853d0983c1ee59370 to your computer and use it in GitHub Desktop.
/*
* Linux altındaki ls komutuna benzer bir komut
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <dirent.h>
#define SUCCESS 1
#define FAILURE 0
int main(int argc, char* argv[])
{
DIR* dir;
struct dirent* file;
struct stat sys_stat;
if (argc > 2)
{
fprintf(stderr, "Hata: parametre kontrolü\n");
exit(FAILURE);
}
//
dir = opendir(argv[1]);
//
if (dir)
{
while ((file = readdir(dir)) != NULL)
{
stat(file->d_name, &sys_stat);
fprintf(stdout, "\033[1m%s\n", file->d_name);
}
}
else
{
exit(SUCCESS);
}
printf("\033[0m");
closedir(dir);
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment