123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
-
- #ifndef SRC_UTIL_FILE_H_
- #define SRC_UTIL_FILE_H_
- #include <stdio.h>
- #include <stdlib.h>
- #include <string>
- #include "util.h"
- #include <functional>
- using namespace std;
- #if defined(__linux__)
- #include <limits.h>
- #endif
- #if defined(_WIN32)
- #ifndef PATH_MAX
- #define PATH_MAX 1024
- #endif
- struct dirent{
- long d_ino;
- off_t d_off;
- unsigned short d_reclen;
- unsigned char d_type;
- char d_name[1];
- };
- typedef struct _dirdesc {
- int dd_fd;
- long dd_loc;
- long dd_size;
- char *dd_buf;
- int dd_len;
- long dd_seek;
- HANDLE handle;
- struct dirent *index;
- } DIR;
- # define __dirfd(dp) ((dp)->dd_fd)
- int mkdir(const char *path, int mode);
- DIR *opendir(const char *);
- int closedir(DIR *);
- struct dirent *readdir(DIR *);
- #endif
- namespace toolkit {
- class File {
- public:
-
- static bool create_path(const char *file, unsigned int mod);
-
- static FILE *create_file(const char *file, const char *mode);
-
- static bool is_dir(const char *path) ;
-
- static bool is_file(const char *path) ;
-
- static bool is_special_dir(const char *path);
-
- static int delete_file(const char *path) ;
-
- static string loadFile(const char *path);
-
- static bool saveFile(const string &data,const char *path);
-
- static string parentDir(const string &path);
-
- static string absolutePath(const string &path, const string ¤tPath,bool canAccessParent = false);
-
- static void scanDir(const string &path,const function<bool(const string &path,bool isDir)> &cb, bool enterSubdirectory = false);
- private:
- File();
- ~File();
- };
- }
- #endif
|