Created
January 30, 2015 15:00
-
-
Save markogresak/6b25a99108a04df02f0b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <string.h> | |
| #include <sys/types.h> | |
| #include <dirent.h> | |
| void ls(char const *path) { | |
| DIR* dir = opendir(path); | |
| struct dirent *entry; | |
| if(dir != NULL) { | |
| printf("Listing directory %s:\n", path); | |
| while((entry = readdir(dir))) | |
| puts(entry->d_name); | |
| closedir (dir); | |
| } | |
| else | |
| printf("Path %s isn't a directory!\n", path); | |
| } | |
| int main(int argc, char const *argv[]) { | |
| if(argv[1]) | |
| ls(argv[1]); | |
| else | |
| ls("./"); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment