mirror of https://github.com/davisking/dlib.git
Made this example simpler
--HG-- extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%402505
This commit is contained in:
parent
6fa91605f8
commit
bfad8f3ef6
|
@ -10,17 +10,12 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include "dlib/dir_nav.h"
|
#include "dlib/dir_nav.h"
|
||||||
#include "dlib/queue.h"
|
#include <vector>
|
||||||
#include "dlib/static_set.h"
|
#include <algorithm>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace dlib;
|
using namespace dlib;
|
||||||
|
|
||||||
typedef queue<directory>::kernel_2a queue_of_dirs;
|
|
||||||
typedef queue<file>::kernel_2a queue_of_files;
|
|
||||||
typedef static_set<file>::kernel_1a set_of_files;
|
|
||||||
typedef static_set<directory>::kernel_1a set_of_dirs;
|
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
@ -34,10 +29,8 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
directory test(loc);
|
directory test(loc);
|
||||||
|
|
||||||
queue_of_dirs dirs;
|
std::vector<directory> dirs;
|
||||||
queue_of_files files;
|
std::vector<file> files;
|
||||||
set_of_dirs sorted_dirs;
|
|
||||||
set_of_files sorted_files;
|
|
||||||
|
|
||||||
cout << "directory: " << test.name() << endl;
|
cout << "directory: " << test.name() << endl;
|
||||||
cout << "full path: " << test.full_name() << endl;
|
cout << "full path: " << test.full_name() << endl;
|
||||||
|
@ -47,38 +40,34 @@ int main(int argc, char** argv)
|
||||||
test.get_dirs(dirs);
|
test.get_dirs(dirs);
|
||||||
test.get_files(files);
|
test.get_files(files);
|
||||||
|
|
||||||
// load the dirs and files into static_sets. This
|
// sort the files and directorys
|
||||||
// seems weird but a static_set can be enumerated in sorted order
|
sort(files.begin(), files.end());
|
||||||
// so this way we can print everything in sorted order. This
|
sort(dirs.begin(), dirs.end());
|
||||||
// static_set also uses a median of three quick sort so the sorting
|
|
||||||
// should be very fast.
|
|
||||||
sorted_files.load(files);
|
|
||||||
sorted_dirs.load(dirs);
|
|
||||||
|
|
||||||
cout << "\n\n\n";
|
cout << "\n\n\n";
|
||||||
|
|
||||||
// print all the subdirectories
|
// print all the subdirectories
|
||||||
while (sorted_dirs.move_next())
|
for (unsigned long i = 0; i < dirs.size(); ++i)
|
||||||
cout << " <DIR> " << sorted_dirs.element().name() << "\n";
|
cout << " <DIR> " << dirs[i].name() << "\n";
|
||||||
|
|
||||||
// print all the subfiles
|
// print all the subfiles
|
||||||
while (sorted_files.move_next())
|
for (unsigned long i = 0; i < files.size(); ++i)
|
||||||
cout << setw(13) << sorted_files.element().size() << " " << sorted_files.element().name() << "\n";
|
cout << setw(13) << files[i].size() << " " << files[i].name() << "\n";
|
||||||
|
|
||||||
|
|
||||||
cout << "\n\nnumber of dirs: " << sorted_dirs.size() << endl;
|
cout << "\n\nnumber of dirs: " << dirs.size() << endl;
|
||||||
cout << "number of files: " << sorted_files.size() << endl;
|
cout << "number of files: " << files.size() << endl;
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (file::file_not_found e)
|
catch (file::file_not_found& e)
|
||||||
{
|
{
|
||||||
cout << "file not found or accessable: " << e.info << endl;
|
cout << "file not found or accessable: " << e.info << endl;
|
||||||
}
|
}
|
||||||
catch (directory::dir_not_found e)
|
catch (directory::dir_not_found& e)
|
||||||
{
|
{
|
||||||
cout << "dir not found or accessable: " << e.info << endl;
|
cout << "dir not found or accessable: " << e.info << endl;
|
||||||
}
|
}
|
||||||
catch (directory::listing_error e)
|
catch (directory::listing_error& e)
|
||||||
{
|
{
|
||||||
cout << "listing error: " << e.info << endl;
|
cout << "listing error: " << e.info << endl;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue