Qore Programming Language Reference Manual
1.12.1
|
This class implements directory handling, file listing, creating/removing subdirectories, etc. More...
Public Member Methods | |
bool | chdir (string path) |
Changes the current directory of the Dir object to the path given. More... | |
nothing | chgrp (int gid) |
Change the group membership of the directory from the group id. More... | |
nothing | chgrp (string groupname) |
Change the group membership of the directory. More... | |
nothing | chmod (softint mode) |
Changes the mode of the directory. More... | |
nothing | chown (int uid) |
Change the ownership of the directory from the userid. More... | |
nothing | chown (string username) |
Change the ownership of the directory from the username. More... | |
constructor (*string encoding) | |
Creates the Directory object. More... | |
copy () | |
Creates a new directory object with the same character encoding specification and the same path as the original. More... | |
int | create (softint mode=0777) |
Creates the directory tree the Dir object points to, if it does not exist. More... | |
bool | exists () |
Returns True if the path in the Dir object points to a directory that already exists and is openable by the current user, False otherwise. More... | |
hash< StatInfo > | hstat () |
Returns a StatInfo hash of file status information for the current directory. More... | |
list< auto > | list (bool full=False) |
Get all entries in this directory, except "." and ".." directories; if any errors occur an exception is thrown. More... | |
list< auto > | list (string regex, softint regex_options=0, softbool full=False) |
Gets all entries in the directory that match the given regular expression (except "." and ".." directories); if any errors occur an exception is thrown. More... | |
list< auto > | listDirs (bool full=False) |
Retrieves all subdirectory entries in this directory, except "." and ".." directories; if any errors occur an exception is thrown. More... | |
list< auto > | listDirs (string regex, softint regex_options=0, softbool full=False) |
Gets all subdirectory entries in the directory that match the given regular expression (except "." and ".." directories); if any errors occur an exception is thrown. More... | |
list< auto > | listFiles (bool full=False) |
Retrieves all files in this directory; if any errors occur an exception is thrown. More... | |
list< auto > | listFiles (string regex, softint regex_options=0, softbool full=False) |
Retrieves all files in the directory that match the given regular expression; if any errors occur an exception is thrown. More... | |
nothing | mkdir (string subdir, softint mode=0777) |
Creates a direct subdirectory in the Dir object's current path. More... | |
Dir | openDir (string subdir, *string encoding) |
Get a Dir object as an subdir entry of the current directory. More... | |
File | openFile (string filename, int flags=O_RDONLY, int mode=0666, *string encoding) |
Create and open a File object in the current directory of the Dir object. More... | |
*string | path () |
Returns the path of the Dir object or NOTHING if no path is set. More... | |
bool | removeFile (string file) |
Remove the file with the given name in the Dir object's directory. More... | |
nothing | rmdir (string subdir) |
Removes a direct subdirectory from the Dir object's current path. More... | |
list< auto > | stat () |
Returns a list of file status information for the current directory. More... | |
hash< FilesystemInfo > | statvfs () |
Returns a FilesystemInfo hash for the current directory. More... | |
This class implements directory handling, file listing, creating/removing subdirectories, etc.
The Dir class allows Qore programs to list and manipulate directories.
Directory objects can be created/opened with a specific character encoding. This means that any entry read from the directory will be tagged with the directory's character encoding. If no character encoding is given the default character encoding is assumed.
bool Qore::Dir::chdir | ( | string | path | ) |
Changes the current directory of the Dir object to the path given.
If this method returns False then the directory can be created by calling Dir::create()
path | The path can be either an absolute path (leading with '/') or a directory relative to the actual path |
"."
have no effectDIR-CHDIR-ERROR | cannot change to relative directory because no current directory is set |
nothing Qore::Dir::chgrp | ( | int | gid | ) |
Change the group membership of the directory from the group id.
gid | the groupid of the user to change the directory to |
DIR-CHOWN-ERROR | cannot change directory owner; no directory is set |
DIR-CHOWN-FAILURE | error changing directory owner (arg will be assigned to the errno value) |
nothing Qore::Dir::chgrp | ( | string | groupname | ) |
Change the group membership of the directory.
groupname | the group name of the group to change the directory to |
DIR-CHGRP-PARAMETER-ERROR | no userid found for user |
DIR-CHOWN-ERROR | cannot change directory owner; no directory is set |
DIR-CHOWN-FAILURE | error changing directory owner (arg will be assigned to the errno value) |
nothing Qore::Dir::chmod | ( | softint | mode | ) |
Changes the mode of the directory.
mode | The mode of the directory |
DIR-CHMOD-ERROR | cannot change directory's mode; no directory is set |
DIR-CHMOD-FAILURE | error changing directory's mode (arg will be assigned to the errno value) |
nothing Qore::Dir::chown | ( | int | uid | ) |
Change the ownership of the directory from the userid.
uid | the userid of the user to change the directory to |
DIR-CHOWN-ERROR | cannot change directory owner; no directory is set |
DIR-CHOWN-FAILURE | error changing directory owner (arg will be assigned to the errno value) |
nothing Qore::Dir::chown | ( | string | username | ) |
Change the ownership of the directory from the username.
username | the username of the user to change the directory to |
DIR-CHOWN-PARAMETER-ERROR | no userid found for user |
DIR-CHOWN-ERROR | cannot change directory owner; no directory is set |
DIR-CHOWN-FAILURE | error changing directory owner (arg will be assigned to the errno value) |
Qore::Dir::constructor | ( | *string | encoding | ) |
Creates the Directory object.
The object will point to the currect directory of the process
encoding | the name of the default character encoding for filenames retrieved; if this argument is not given, filename strings retrieved will be tagged with the default character encoding of the process |
Qore::Dir::copy | ( | ) |
Creates a new directory object with the same character encoding specification and the same path as the original.
int Qore::Dir::create | ( | softint | mode = 0777 | ) |
Creates the directory tree the Dir object points to, if it does not exist.
mode | The mode of the directory |
DIR-CREATE-ERROR | cannot create directory; no directory is set |
DIR-CREATE-FAILURE | error creating directory (arg will be assigned to the errno value) |
bool Qore::Dir::exists | ( | ) |
Returns True if the path in the Dir object points to a directory that already exists and is openable by the current user, False otherwise.
Returns a StatInfo hash of file status information for the current directory.
If any errors occur an exception will be thrown
DIR-HSTAT-ERROR | no directory is set |
DIR-HSTAT-FAILURE | error stat'ing directory (arg will be assigned to the errno value) |
list<auto> Qore::Dir::list | ( | bool | full = False | ) |
Get all entries in this directory, except "."
and ".."
directories; if any errors occur an exception is thrown.
This method uses stat()
system call internally to get detailed info about directory entries if the full
parameter is True. If a stat() call fails for an entry, the entry is skipped and information about it is not included in the returned list.
full | if True then the return value is a list of DirStatInfo hashes, otherwise a simple list of string names is returned |
"."
and ".."
directories); if full is True, then the return value is a list of DirStatInfo hashes, otherwise a simple list of string names is returnedDIR-READ-ERROR | no directory is set |
DIR-READ-FAILURE | error reading directory (arg will be assigned to the errno value) |
Gets all entries in the directory that match the given regular expression (except "."
and ".."
directories); if any errors occur an exception is thrown.
This method uses stat()
system call internally to get info about directory entries. If a stat() call fails for an entry, the entry is skipped and information about it is not included in the returned list.
regex | a regular expression string used to filter the arguments (note that this is not a glob, but rather a regular expression string) |
regex_options | optional bitwise-or'ed regex option constants |
full | if True then the return value is a list of DirStatInfo hashes, otherwise a simple list of string names is returned |
"."
and ".."
directories); if full is True, then the return value is a list of DirStatInfo hashes, otherwise a simple list of string names is returnedDIR-READ-ERROR | no directory is set |
DIR-READ-FAILURE | error reading directory (arg will be assigned to the errno value) |
REGEX-COMPILATION-ERROR | error in regular expression |
REGEX-OPTION-ERROR | regex option argument contains invalid option bits |
Retrieves all subdirectory entries in this directory, except "."
and ".."
directories; if any errors occur an exception is thrown.
This method uses stat()
system call internally to get info about directory entries. If a stat() call fails for an entry, the entry is skipped and information about it is not included in the returned list.
full | if True then the return value is a list of DirStatInfo hashes, otherwise a simple list of string names is returned |
"."
and ".."
directories; if full is True, then the return value is a list of DirStatInfo hashes, otherwise a simple list of string names is returnedDIR-READ-ERROR | no directory is set |
DIR-READ-FAILURE | error reading directory (arg will be assigned to the errno value) |
Gets all subdirectory entries in the directory that match the given regular expression (except "."
and ".."
directories); if any errors occur an exception is thrown.
This method uses stat()
system call internally to get info about directory entries. If a stat() call fails for an entry, the entry is skipped and information about it is not included in the returned list.
regex | a regular expression string used to filter the arguments (note that this is not a glob, but rather a regular expression string) |
regex_options | optional bitwise-or'ed regex option constants |
full | if True then the return value is a list of DirStatInfo hashes, otherwise a simple list of string names is returned |
"."
and ".."
directories); if full is True, then the return value is a list of DirStatInfo hashes, otherwise a simple list of string names is returnedDIR-READ-ERROR | no directory is set |
DIR-READ-FAILURE | error reading directory (arg will be assigned to the errno value) |
REGEX-COMPILATION-ERROR | error in regular expression |
REGEX-OPTION-ERROR | regex option argument contains invalid option bits |
Retrieves all files in this directory; if any errors occur an exception is thrown.
This method uses stat()
system call internally to get info about directory entries. If a stat() call fails for a file, the file is skipped and information about this file is not included in the returned list.
full | if True then the return value is a list of DirStatInfo hashes, otherwise a simple list of string names is returned |
DIR-READ-ERROR | no directory is set |
DIR-READ-FAILURE | error reading directory (arg will be assigned to the errno value) |
Retrieves all files in the directory that match the given regular expression; if any errors occur an exception is thrown.
This method uses stat()
system call internally to get info about directory entries. If a stat() call fails for a file, the file is skipped and information about this file is not included in the returned list.
regex | a regular expression string used to filter the arguments (note that this is not a glob, but rather a regular expression string) |
regex_options | optional bitwise-or'ed regex option constants |
full | if True then the return value is a list of DirStatInfo hashes, otherwise a simple list of string names is returned |
DIR-READ-ERROR | no directory is set |
DIR-READ-FAILURE | error reading directory (arg will be assigned to the errno value) |
REGEX-COMPILATION-ERROR | error in regular expression |
REGEX-OPTION-ERROR | regex option argument contains invalid option bits |
nothing Qore::Dir::mkdir | ( | string | subdir, |
softint | mode = 0777 |
||
) |
Creates a direct subdirectory in the Dir object's current path.
subdir | The subdirectory name to create; only direct subdirectories are allowed; directory separator characters are not allowed |
mode | The mode of the directory |
DIR-MKDIR-PARAMETER-ERROR | only direct subdirectories are allowed |
DIR-MKDIR-FAILURE | error creating directory (arg will be assigned to the errno value) |
Get a Dir object as an subdir entry of the current directory.
subdir | The name of the subdirectory for the new Dir object (which must be in the current directory of the current Dir object; no path separator characters are allowed) |
encoding | The name of the default character encoding for the new Dir object; if this argument is not given, the new Dir object will be tagged with the character encoding of the current Dir object |
DIR-OPENDIR-PARAMETER-ERROR | only direct subdirectory names without path separators are allowed |
File Qore::Dir::openFile | ( | string | filename, |
int | flags = O_RDONLY , |
||
int | mode = 0666 , |
||
*string | encoding | ||
) |
Create and open a File object in the current directory of the Dir object.
This method uses the File::open2() method to open the file.
filename | The filename for the file which must be in the current directory (no path separator characters are allowed) |
flags | Flags that determine the way the file is accessed, see File Open Constants for more information |
mode | Permission bits for when the file is to be created |
encoding | The name of the default character encoding for this file; if this argument is not given, the file will be tagged with the default character encoding for the process |
DIR-OPENFILE-PARAMETER-ERROR | only direct subdirectory names without path separators are allowed |
*string Qore::Dir::path | ( | ) |
bool Qore::Dir::removeFile | ( | string | file | ) |
Remove the file with the given name in the Dir object's directory.
If any errors occur unlinking the file, then an exception occurs
file | Remove the file with the given name in the Dir object's directory |
DIR-REMOVEFILE-PARAMETER-ERROR | only filenames without path (i.e. without path separator characters) are allowed |
DIR-REMOVEFILE-FAILURE | the unlink() function returned an error (arg will be assigned to the errno value) |
nothing Qore::Dir::rmdir | ( | string | subdir | ) |
Removes a direct subdirectory from the Dir object's current path.
subdir | The subdirectory name to remove; only direct subdirectories are allowed; directory separator characters are not allowed |
DIR-RMDIR-PARAMETER-ERROR | only direct subdirectories are allowed |
DIR-RMDIR-FAILURE | error removing directory (arg will be assigned to the errno value) |
list<auto> Qore::Dir::stat | ( | ) |
Returns a list of file status information for the current directory.
If any errors occur an exception will be thrown
DIR-STAT-ERROR | no directory is set |
DIR-STAT-FAILURE | error stat'ing directory (arg will be assigned to the errno value) |
hash<FilesystemInfo> Qore::Dir::statvfs | ( | ) |
Returns a FilesystemInfo hash for the current directory.
DIR-STATVFS-ERROR | no directory is set |
DIR-STATVFS-FAILURE | error in statvfs (arg will be assigned to the errno value) |