Qore Programming Language  1.12.0
QoreDir Class Reference

provides controlled access to the filesystem through directories More...

#include <QoreDir.h>

Inherited by Dir.

Public Member Methods

DLLEXPORT QoreDir (ExceptionSink *xsink, const QoreDir &old)
 copies the object More...
 
DLLEXPORT QoreDir (ExceptionSink *xsink, const QoreEncoding *cs=QCS_DEFAULT, const char *dir=nullptr)
 creates the object and sets the default encoding More...
 
DLLEXPORT ~QoreDir ()
 closes the directory and frees all memory allocated to the object
 
DLLEXPORT int chdir (const char *dir)
 changes the directory in relation to the current More...
 
DLLEXPORT int chdir (const char *dir, ExceptionSink *xsink)
 changes the directory in relation to the current More...
 
DLLEXPORT int checkPath () const
 returns 0 = OK (path exists), non-zero = errno returned by opendir() More...
 
DLLEXPORT int chmod (int mode, ExceptionSink *xsink) const
 changes the mode of the current directory More...
 
DLLEXPORT int create (int mode) const
 creates the current directory, including all parent directories, if they do not exist More...
 
DLLEXPORT int create (int mode, ExceptionSink *xsink) const
 creates the current directory, including all parent directories, if they do not exist More...
 
DLLEXPORT QoreStringNodedirname () const
 returns the current directory name or 0 if none is set More...
 
DLLEXPORT const QoreEncodinggetEncoding () const
 returns the encoding used for the filesystem More...
 
DLLEXPORT std::string getPath (const char *sub) const
 returns a complete path with the argument appended to the current directory name More...
 
DLLEXPORT QoreHashNodehstat (ExceptionSink *xsink) const
 returns a QoreHashNode with directory status information More...
 
DLLEXPORT QoreListNodelist (ExceptionSink *xsink, int stat_filter, const QoreString *regex=nullptr, int regex_options=0, bool full=false) const
 returns a list of files in the current directory, taking an option regular expression filter More...
 
DLLEXPORT int mkdir (ExceptionSink *xsink, const char *subdir, int mode=0777) const
 creates a subdirectory of the current directory More...
 
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 More...
 
DLLEXPORT int rmdir (const char *subdir, ExceptionSink *xsink) const
 removes a subdirectory of the current directory More...
 
DLLEXPORT QoreListNodestat (ExceptionSink *xsink) const
 returns a QoreListNode with directory status information More...
 
DLLEXPORT QoreHashNodestatvfs (ExceptionSink *xsink) const
 returns a QoreHashNode with filesystem status information More...
 

Static Public Member Methods

static DLLEXPORT bool file_exists (const QoreString &filePath)
 checks whether file exists More...
 
static DLLEXPORT bool folder_exists (const QoreString &folderPath, ExceptionSink &xsink, const QoreEncoding *cs=QCS_DEFAULT)
 checks whether folder exists More...
 
static DLLEXPORT std::string get_file_content (const QoreString &fullPath)
 reads file content More...
 
static DLLEXPORT QoreListNodeget_files (const QoreString &path, ExceptionSink &xsink, QoreString *regex=nullptr, const QoreEncoding *cs=QCS_DEFAULT)
 look up files More...
 

Detailed Description

provides controlled access to the filesystem through directories

Each QoreDir object has a default character encoding associated with it. The class is thread-safe.

See also
QoreEncoding

Constructor & Destructor Documentation

◆ QoreDir() [1/2]

DLLEXPORT QoreDir::QoreDir ( ExceptionSink xsink,
const QoreEncoding cs = QCS_DEFAULT,
const char *  dir = nullptr 
)

creates the object and sets the default encoding

Parameters
xsinkif an out of memory error occurs in the constructor
csthe encoding to use for this directory
dirthe initial directory; 0 = the current directory

◆ QoreDir() [2/2]

DLLEXPORT QoreDir::QoreDir ( ExceptionSink xsink,
const QoreDir old 
)

copies the object

Parameters
xsinka Qore-language exception can be raised only on out of memory
oldthe old object to copy

Member Function Documentation

◆ chdir() [1/2]

DLLEXPORT int QoreDir::chdir ( const char *  dir)

changes the directory in relation to the current

Parameters
dirthe directory to change to. can include .. and .
Returns
0 for success, -1 for error

◆ chdir() [2/2]

DLLEXPORT int QoreDir::chdir ( const char *  dir,
ExceptionSink xsink 
)

changes the directory in relation to the current

Parameters
dirthe directory to change to. can include .. and .
xsinkif the path is relative and no current directory is set, a qore-language exception is thrown
Returns
0 for success

◆ checkPath()

DLLEXPORT int QoreDir::checkPath ( ) const

returns 0 = OK (path exists), non-zero = errno returned by opendir()

Returns
0 = OK (path exists), non-zero = errno returned by opendir()

◆ chmod()

DLLEXPORT int QoreDir::chmod ( int  mode,
ExceptionSink xsink 
) const

changes the mode of the current directory

Parameters
modethe moddoe to change the directory to
xsinkif errors occur, qore-language exception information is added here
Returns
0 = OK, -1 = an exception was raised

◆ create() [1/2]

DLLEXPORT int QoreDir::create ( int  mode) const

creates the current directory, including all parent directories, if they do not exist

Parameters
modethe mode for any directoreis created
Returns
the number of directories created, -1 = error
Since
Qore 0.9.5

◆ create() [2/2]

DLLEXPORT int QoreDir::create ( int  mode,
ExceptionSink xsink 
) const

creates the current directory, including all parent directories, if they do not exist

Parameters
modethe mode for any directoreis created
xsinkif errors occur, qore-language exception information is added here
Returns
the number of directories created, -1 = error

◆ dirname()

DLLEXPORT QoreStringNode* QoreDir::dirname ( ) const

returns the current directory name or 0 if none is set

Returns
the current directory name or 0 if none is set

◆ file_exists()

static DLLEXPORT bool QoreDir::file_exists ( const QoreString filePath)
static

checks whether file exists

Parameters
filePathfile path
Returns
true if file exists

◆ folder_exists()

static DLLEXPORT bool QoreDir::folder_exists ( const QoreString folderPath,
ExceptionSink xsink,
const QoreEncoding cs = QCS_DEFAULT 
)
static

checks whether folder exists

Parameters
folderPathfolder path
xsinka Qore-language exception can be raised only on out of memory
csthe encoding to use for this directory return 0 = OK (folder exists) non-zero = errno returned by opendir()

◆ get_file_content()

static DLLEXPORT std::string QoreDir::get_file_content ( const QoreString fullPath)
static

reads file content

Parameters
fullPathfile name
Returns
file content

◆ get_files()

static DLLEXPORT QoreListNode* QoreDir::get_files ( const QoreString path,
ExceptionSink xsink,
QoreString regex = nullptr,
const QoreEncoding cs = QCS_DEFAULT 
)
static

look up files

Parameters
pathpath where files should be looked up
xsinka Qore-language exception can be raised only on out of memory
regexfilter
csthe encoding to use for this directory
Returns
list of files

◆ getEncoding()

DLLEXPORT const QoreEncoding* QoreDir::getEncoding ( ) const

returns the encoding used for the filesystem

Returns
the encoding used for the filesystem

◆ getPath()

DLLEXPORT std::string QoreDir::getPath ( const char *  sub) const

returns a complete path with the argument appended to the current directory name

Parameters
subthe subdirectory name to append to the current directory name
Returns
a complete path with the argument appended to the current directory name

◆ hstat()

DLLEXPORT QoreHashNode* QoreDir::hstat ( ExceptionSink xsink) const

returns a QoreHashNode with directory status information

Parameters
xsinkif an error occurs, the Qore-language exception info will be added here
Returns
a QoreHashNode with directory status information

◆ list()

DLLEXPORT QoreListNode* QoreDir::list ( ExceptionSink xsink,
int  stat_filter,
const QoreString regex = nullptr,
int  regex_options = 0,
bool  full = false 
) const

returns a list of files in the current directory, taking an option regular expression filter

Parameters
xsinkif errors occur, qore-language exception information is added here
stat_filterset to -1 to get everything, otherwise use S_* constants from stat() to filter for particular file types
regexan optional regular expression to filter the resulting list
regex_optionsoptional regular expression options
fullif false a list of file name is returned, if true then a list of hashes corresponding to the stat() information is returned
Returns
a list of the results

◆ mkdir()

DLLEXPORT int QoreDir::mkdir ( ExceptionSink xsink,
const char *  subdir,
int  mode = 0777 
) const

creates a subdirectory of the current directory

Parameters
xsinkif an error occurs, qore-language exception information is added here
subdirthe subdirectory name to create
modethe mode of the directory to create (default = 0777)
Returns
0 = OK, -1 = an exception was raised

◆ openFile()

DLLEXPORT QoreFile QoreDir::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

Parameters
xsinkif errors occur, qore-language exception information is added here
fnthe name of the file to be opened
flagsthe flags to use when opening the file
modethe mode mask to use when opening the file
csthe encoding to use for the file
Returns
the File class, throws an exception on error

◆ rmdir()

DLLEXPORT int QoreDir::rmdir ( const char *  subdir,
ExceptionSink xsink 
) const

removes a subdirectory of the current directory

Parameters
subdirthe subdirectory name to remove
xsinkif errors occur, qore-language exception information is added here
Returns
0 = OK, -1 = an exception was raised

◆ stat()

DLLEXPORT QoreListNode* QoreDir::stat ( ExceptionSink xsink) const

returns a QoreListNode with directory status information

Parameters
xsinkif an error occurs, the Qore-language exception info will be added here
Returns
a QoreListNode with directory status information

◆ statvfs()

DLLEXPORT QoreHashNode* QoreDir::statvfs ( ExceptionSink xsink) const

returns a QoreHashNode with filesystem status information

Parameters
xsinkif an error occurs, the Qore-language exception info will be added here
Returns
a QoreHashNode with filesystem status information

The documentation for this class was generated from the following file: