///////////////////////////////////////////////////////////////////////////////
// FileList.h
// Copyright Björn Ganster
///////////////////////////////////////////////////////////////////////////////


#ifndef FileList__H
#define FileList__H

#include "BGBase.h"
#include "BGCPString.h"

#ifdef WIN32
#define chdir _chdir
#define getcwd _getcwd
#else
#include <dirent.h> 
#endif

class FileList: public VirtualClass {
public:
   // Constructor: list all files, with wild cards
   FileList ();

   // Destructor
   ~FileList ();

   bool start (const PathChar* path);

   // Get members
   const PathChar* getFileName() const;
   INT64 getSize() const;

   // Navigate
   bool operator++();

   // Find first match for mask
   static bool findFirstMatch (const PathChar* mask, BGCPString& result);

   bool isDirectory();
private:
#ifdef _WIN32
   WIN32_FIND_DATAW FindFileData;
   HANDLE hFind;
#else
   DIR* dir;
   dirent* entry;
   BGCPString m_path, mask;
   bool matches() const;
   bool isDir;
   size_t size;
   void getStats(const char* fn);
#endif
};

#endif
