Qore Programming Language  0.9.4.6
QoreDir.h
1 /* -*- mode: c++; indent-tabs-mode: nil -*- */
2 /*
3  QoreDir.h
4 
5  thread-safe Directory object with a private implementation
6 
7  Qore Programming Language
8 
9  Copyright (C) 2003 - 2016 David Nichols
10 
11  Permission is hereby granted, free of charge, to any person obtaining a
12  copy of this software and associated documentation files (the "Software"),
13  to deal in the Software without restriction, including without limitation
14  the rights to use, copy, modify, merge, publish, distribute, sublicense,
15  and/or sell copies of the Software, and to permit persons to whom the
16  Software is furnished to do so, subject to the following conditions:
17 
18  The above copyright notice and this permission notice shall be included in
19  all copies or substantial portions of the Software.
20 
21  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  DEALINGS IN THE SOFTWARE.
28 
29  Note that the Qore library is released under a choice of three open-source
30  licenses: MIT (as above), LGPL 2+, or GPL 2+; see README-LICENSE for more
31  information.
32 */
33 
34 #ifndef _QORE_QOREDIR_H
35 
36 #define _QORE_QOREDIR_H
37 
38 #include <dirent.h>
39 #include <string>
40 #include <vector>
41 
42 #ifndef HAVE_DIRENT_D_TYPE
43 #include <sys/stat.h>
44 #include <sys/types.h>
45 #include <unistd.h>
46 
47 #endif
48 
50 
53 class QoreDir {
54 private:
56  class qore_qd_private *priv;
57 
59  DLLLOCAL QoreDir(const QoreDir&);
60 
62  DLLLOCAL QoreDir& operator=(const QoreDir&);
63 
64 public:
66 
70  DLLEXPORT static bool file_exists(const QoreString& filePath);
71 
73 
79  DLLEXPORT static bool folder_exists(const QoreString& folderPath, ExceptionSink& xsink, const QoreEncoding* cs = QCS_DEFAULT);
80 
82 
86  DLLEXPORT static std::string get_file_content(const QoreString& fullPath);
87 
89 
96  DLLEXPORT static QoreListNode* get_files(const QoreString& path, ExceptionSink& xsink, QoreString* regex = nullptr, const QoreEncoding* cs = QCS_DEFAULT);
97 
99 
104  DLLEXPORT QoreDir(ExceptionSink *xsink, const QoreEncoding *cs = QCS_DEFAULT, const char *dir = 0);
105 
107 
110  DLLEXPORT QoreDir(ExceptionSink *xsink, const QoreDir &old);
111 
113  DLLEXPORT ~QoreDir();
114 
116 
121  DLLEXPORT int chdir(const char* dir, ExceptionSink *xsink);
122 
124 
129  DLLEXPORT int mkdir(ExceptionSink *xsink, const char *subdir, int mode = 0777) const;
130 
132 
136  DLLEXPORT int rmdir(const char *subdir, ExceptionSink *xsink) const;
137 
139 
143  DLLEXPORT int chmod(int mode, ExceptionSink *xsink) const;
144 
145 #ifdef HAVE_PWD_H
146 
152  DLLEXPORT int chown(uid_t uid, gid_t gid, ExceptionSink *xsink) const;
153 #endif
154 
156 
160  DLLEXPORT int create(int mode, ExceptionSink *xsink) const;
161 
163 
165  DLLEXPORT int checkPath() const;
166 
168 
170  DLLEXPORT QoreStringNode *dirname() const;
171 
173 
176  DLLEXPORT std::string getPath(const char *sub) const;
177 
179 
181  DLLEXPORT const QoreEncoding *getEncoding() const;
182 
184 
192  DLLEXPORT QoreFile openFile(ExceptionSink *xsink, const char* fn, int flags = O_RDONLY, int mode = 0777, const QoreEncoding *cs = QCS_DEFAULT);
193 
195 
202  DLLEXPORT QoreListNode* list(ExceptionSink *xsink, int stat_filter, const QoreString *regex = 0, int regex_options = 0, bool full = false) const;
203 
205 
208  DLLEXPORT QoreListNode *stat(ExceptionSink *xsink) const;
209 
211 
214  DLLEXPORT QoreHashNode *hstat(ExceptionSink *xsink) const;
215 
217 
220  DLLEXPORT QoreHashNode *statvfs(ExceptionSink *xsink) const;
221 };
222 
223 #endif // _QORE_QOREDIR_H
DLLEXPORT int chmod(int mode, ExceptionSink *xsink) const
changes the mode of the current directory
DLLEXPORT QoreListNode * list(ExceptionSink *xsink, int stat_filter, const QoreString *regex=0, int regex_options=0, bool full=false) const
returns a list of files in the current directory, taking an option regular expression filter ...
defines string encoding functions in Qore
Definition: QoreEncoding.h:83
This is the hash or associative list container type in Qore, dynamically allocated only...
Definition: QoreHashNode.h:50
DLLEXPORT const QoreEncoding * QCS_DEFAULT
the default encoding for the Qore library
DLLEXPORT int checkPath() const
returns 0 = OK (path exists), non-zero = errno returned by opendir()
DLLEXPORT QoreListNode * stat(ExceptionSink *xsink) const
returns a QoreListNode with directory status information
static DLLEXPORT QoreListNode * get_files(const QoreString &path, ExceptionSink &xsink, QoreString *regex=nullptr, const QoreEncoding *cs=QCS_DEFAULT)
look up files
DLLEXPORT std::string getPath(const char *sub) const
returns a complete path with the argument appended to the current directory name
Qore&#39;s string type supported by the QoreEncoding class.
Definition: QoreString.h:81
Qore&#39;s string value type, reference counted, dynamically-allocated only.
Definition: QoreStringNode.h:50
DLLEXPORT QoreHashNode * statvfs(ExceptionSink *xsink) const
returns a QoreHashNode with filesystem status information
This is the list container type in Qore, dynamically allocated only, reference counted.
Definition: QoreListNode.h:52
provides controlled access to the filesystem through directories
Definition: QoreDir.h:53
static DLLEXPORT bool folder_exists(const QoreString &folderPath, ExceptionSink &xsink, const QoreEncoding *cs=QCS_DEFAULT)
checks whether folder exists
DLLEXPORT int create(int mode, ExceptionSink *xsink) const
creates the current directory, including all parent directories, if they do not exist ...
provides controlled access to file data through Qore data structures
Definition: QoreFile.h:66
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:46
static DLLEXPORT bool file_exists(const QoreString &filePath)
checks whether file exists
DLLEXPORT int rmdir(const char *subdir, ExceptionSink *xsink) const
removes a subdirectory of the current directory
DLLEXPORT int chdir(const char *dir, ExceptionSink *xsink)
changes the directory in relation to the current
static DLLEXPORT std::string get_file_content(const QoreString &fullPath)
reads file content
DLLEXPORT QoreFile openFile(ExceptionSink *xsink, const char *fn, int flags=O_RDONLY, int mode=0777, const QoreEncoding *cs=QCS_DEFAULT)
returns a new file in this directory
DLLEXPORT const QoreEncoding * getEncoding() const
returns the encoding used for the filesystem
DLLEXPORT ~QoreDir()
closes the directory and frees all memory allocated to the object
DLLEXPORT int mkdir(ExceptionSink *xsink, const char *subdir, int mode=0777) const
creates a subdirectory of the current directory
DLLEXPORT QoreStringNode * dirname() const
returns the current directory name or 0 if none is set
DLLEXPORT QoreHashNode * hstat(ExceptionSink *xsink) const
returns a QoreHashNode with directory status information