Skip to content

Instantly share code, notes, and snippets.

@thinkphp
Created October 31, 2018 16:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thinkphp/c39c2595dfccf3fad7fa629a2c5b50b5 to your computer and use it in GitHub Desktop.
Save thinkphp/c39c2595dfccf3fad7fa629a2c5b50b5 to your computer and use it in GitHub Desktop.
Reads the contents of a root directory
/**
This example reads the contents of a root directory.
Reference: https://www.ibm.com/support/knowledgecenter/en/SSLTBW_2.3.0/com.ibm.zos.v2r3.bpxbd00/rtread.htm
*/
#include <stdio.h>
#include <dirent.h>
#include <errno.h>
int main() {
DIR *dir;
struct dirent *entry;
if((dir = opendir("/home/adrian")) == NULL) {
perror("opendir() error");
} else {
puts("Contents of root:");
while((entry = readdir(dir)) != NULL )
printf(" %s\n", entry->d_name);
closedir( dir );
}
return(0);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment