#include "Directory.h"
#include <iostream>
#include <unistd.h>
#include <string.h>



int main( int argc, char * argv [] ) {

  if ( argc < 2 ) {
    std::cout << "usage: ExampleDirectoy Dir [regexp]\n";
    exit (1);
  }

  try {
    if ( ! compp::DirEntry::Exist ( argv [1] ) ) {
      std::cout << argv [1] << " does not exist.\n";
      exit (1);
    }

    compp::Directory dir ; 

    if ( argc == 2 )
      dir.setPath ( argv [ 1 ] ); 
    else
      dir.setPath ( argv [ 1 ], argv [ 2 ] ); 

    dir.setSortDesc();
    dir.SortName();

    std::list<compp::DirEntry>::iterator it = dir.getFirst();
    

    while ( it != dir.end() ) {
      compp::DirEntry ent = *it;
      std::cout << ent.getName() << "\n";
      
      ++ it;
      
    }

    
  } catch ( syspp::ComException & e ) {
    std::cout << "Exception " << e.what() << "\n";    
  }  
    
  return 0;
}
