2010-05-16 19:26:45 -04:00
|
|
|
#ifndef FOLDERITERATOR_H
|
|
|
|
#define FOLDERITERATOR_H
|
|
|
|
|
|
|
|
|
2016-07-23 22:14:43 -04:00
|
|
|
#include <stdint.h>
|
2010-05-16 19:26:45 -04:00
|
|
|
#include <iostream>
|
|
|
|
#include <cstdio>
|
|
|
|
|
|
|
|
#ifdef WINDOWS_SYS
|
|
|
|
#include <windows.h>
|
|
|
|
#include <tchar.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#else
|
|
|
|
#include <dirent.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
namespace librs { namespace util {
|
|
|
|
|
|
|
|
|
|
|
|
class FolderIterator
|
|
|
|
{
|
|
|
|
public:
|
2016-11-16 15:49:27 -05:00
|
|
|
FolderIterator(const std::string& folderName,bool allow_symlinks,bool allow_files_from_the_future = true);
|
2010-05-16 19:26:45 -04:00
|
|
|
~FolderIterator();
|
|
|
|
|
2016-07-23 22:14:43 -04:00
|
|
|
enum { TYPE_UNKNOWN = 0x00,
|
|
|
|
TYPE_FILE = 0x01,
|
|
|
|
TYPE_DIR = 0x02
|
|
|
|
};
|
2010-05-16 19:26:45 -04:00
|
|
|
|
2016-09-15 15:45:00 -04:00
|
|
|
// info about current parent directory
|
|
|
|
time_t dir_modtime() const ;
|
|
|
|
|
|
|
|
// info about directory content
|
|
|
|
|
2016-07-23 22:14:43 -04:00
|
|
|
bool isValid() const { return validity; }
|
2010-05-16 19:26:45 -04:00
|
|
|
bool readdir();
|
2016-07-23 22:14:43 -04:00
|
|
|
void next();
|
2010-05-16 19:26:45 -04:00
|
|
|
|
|
|
|
bool closedir();
|
|
|
|
|
2016-07-23 22:14:43 -04:00
|
|
|
const std::string& file_name() ;
|
|
|
|
const std::string& file_fullpath() ;
|
|
|
|
uint64_t file_size() ;
|
2016-07-24 23:48:22 -04:00
|
|
|
uint8_t file_type() ;
|
2016-07-23 22:14:43 -04:00
|
|
|
time_t file_modtime() ;
|
|
|
|
|
2010-05-16 19:26:45 -04:00
|
|
|
private:
|
2016-09-24 07:56:02 -04:00
|
|
|
bool is_open;
|
2010-05-16 19:26:45 -04:00
|
|
|
bool validity;
|
|
|
|
|
|
|
|
#ifdef WINDOWS_SYS
|
|
|
|
HANDLE handle;
|
|
|
|
bool isFirstCall;
|
|
|
|
_WIN32_FIND_DATAW fileInfo;
|
|
|
|
#else
|
|
|
|
DIR* handle;
|
2010-05-16 19:59:39 -04:00
|
|
|
struct dirent* ent;
|
2010-05-16 19:26:45 -04:00
|
|
|
#endif
|
2016-11-14 08:10:49 -05:00
|
|
|
bool updateFileInfo(bool &should_skip) ;
|
2016-07-23 22:14:43 -04:00
|
|
|
|
|
|
|
time_t mFileModTime ;
|
2016-09-15 15:45:00 -04:00
|
|
|
time_t mFolderModTime ;
|
2016-07-23 22:14:43 -04:00
|
|
|
uint64_t mFileSize ;
|
|
|
|
uint8_t mType ;
|
|
|
|
std::string mFileName ;
|
|
|
|
std::string mFullPath ;
|
|
|
|
std::string mFolderName ;
|
2016-11-16 15:41:32 -05:00
|
|
|
bool mAllowSymLinks;
|
2016-11-16 15:49:27 -05:00
|
|
|
bool mAllowFilesFromTheFuture;
|
2010-05-16 19:26:45 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} } // librs::util
|
|
|
|
|
|
|
|
|
|
|
|
#endif // FOLDERITERATOR_H
|