File: Find.cc

package info (click to toggle)
exactimage 1.2.1-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 3,048 kB
  • sloc: cpp: 35,940; ansic: 1,952; xml: 1,447; makefile: 338; perl: 138; sh: 110; python: 45; php: 37; ruby: 12
file content (46 lines) | stat: -rw-r--r-- 871 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46

#include <iostream>
#include <sstream>

#include <deque>

#include "DirIterator.hh"

// !sorted might be faster but less sorted ...
const bool sorted = true;

std::deque<std::string> todo_queue;

void scan (const std::string s)
{
  Utility::DirList dir (s);
  Utility::DirList::Iterator it (dir.Begin());
  Utility::DirList::Iterator it_end (dir.End ());
  
  while  (it != it_end) {
    std::cout << s + '/' + *it << std::endl;
    if (it.Type().IsDirectory()) {
      if (sorted)
        scan (s + '/' + *it);
      else
        todo_queue.push_back (s + '/' + *it);
    }
    ++ it;
  }

  if (!sorted)
    while (todo_queue.size() > 0) {
      std::string ts (todo_queue.front());
      todo_queue.pop_front();
      scan(ts);
    }
}

int main (int argc, char* argv[])
{
  std::string start ("/home/rene");
  if (argc > 1)
    start = argv[1];
  
  scan (start);
}