-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFile_old.h
66 lines (55 loc) · 1.36 KB
/
File_old.h
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
* \file File_old.h
* \brief File class, similar to java.io.File, though lacking functionality
*/
#include <string>
#if defined(_POSIX)
#include <unistd.h>
#include <dirent.h>
#include <sys/stat.h>
#elif defined(_WIN32)
#include <windows.h>
#include <sys/stat.h>
#else
#error Couldn’t detect correct OS
#endif
//--------------------------------------------------------------------------------------------------
using namespace std;
class File
{
public:
File(const string &filePath) :
path(filePath)
{
}
virtual ~File()
{
}
bool isDirectory() const
{
#ifdef _POSIX
struct stat sbuf;
if (stat(path.c_str(), &sbuf) == -1)
return false;
return (sbuf.st_mode & _S_IFDIR)!=0;
#elif defined(_WIN32)
struct _stati64 sbuf;
if (_stati64(path.c_str(), &sbuf)==-1)
return false;
return (sbuf.st_mode & _S_IFDIR)!=0;
#endif
}
bool exists() const
{
#ifdef _POSIX
struct stat sbuf;
return stat(path.c_str(), &sbuf)!=-1;
#elif defined(_WIN32)
return GetFileAttributes(path.c_str()) != INVALID_FILE_ATTRIBUTES;
#endif
}
protected:
string path;
///< the path to the file
};
//--------------------------------------------------------------------------------------------------