source: testjes/testdirent.cpp @ 10

Last change on this file since 10 was 10, checked in by willem, 11 years ago

willem

File size: 627 bytes
Line 
1#include <iostream>
2#include <list>
3#include <stdio.h>
4#include <errno.h>
5#include <dirent.h>
6int main()
7{
8  DIR *dir;
9  struct dirent *ent;
10  if ((dir = opendir (".")) != NULL) {
11    std::list <std::string> v;
12    while ((ent = readdir (dir)) != NULL) {
13      v.push_back(ent->d_name);
14    }
15    closedir (dir);
16    v.sort();
17    std::string a;
18    for (std::list<std::string>::iterator it=v.begin(); it != v.end(); ++it)
19    {
20      if ((*it).size() >=1 && (*it)[0] != '.')
21        a += *it + " ";
22    }
23    std::cout << a << std::endl;
24  } else {
25    /* could not open directory */
26    perror ("");
27    return 1;
28  }
29  return 0;
30}
Note: See TracBrowser for help on using the repository browser.