Qore Programming Language Reference Manual 2.0.0
|
This class implements directory handling, file listing, creating/removing subdirectories, etc. More...
#include <QC_Dir.dox.h>
Public Member Methods | |
bool | chdir (string path) |
Changes the current directory of the Dir object to the path given. | |
nothing | chgrp (int gid) |
Change the group membership of the directory from the group id. | |
nothing | chgrp (string groupname) |
Change the group membership of the directory. | |
nothing | chmod (softint mode) |
Changes the mode of the directory. | |
nothing | chown (int uid) |
Change the ownership of the directory from the userid. | |
nothing | chown (string username) |
Change the ownership of the directory from the username. | |
constructor (__7_ string encoding) | |
Creates the Directory object. | |
copy () | |
Creates a new directory object with the same character encoding specification and the same path as the original. | |
int | create (softint mode=0777) |
Creates the directory tree the Dir object points to, if it does not exist. | |
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. | |
hash< StatInfo > | hstat () |
Returns a StatInfo hash of file status information for the current directory. | |
list< auto > | list (bool full=False) |
Get all entries in this directory, except "." and ".." directories; if any errors occur an exception is thrown. | |
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. | |
list< auto > | listDirs (bool full=False) |
Retrieves all subdirectory entries in this directory, except "." and ".." directories; if any errors occur an exception is thrown. | |
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. | |
list< auto > | listFiles (bool full=False) |
Retrieves all files in this directory; if any errors occur an exception is thrown. | |
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. | |
nothing | mkdir (string subdir, softint mode=0777) |
Creates a direct subdirectory in the Dir object's current path. | |
Dir | openDir (string subdir, __7_ string encoding) |
Get a Dir object as an subdir entry of the current directory. | |
File | openFile (string filename, int flags=O_RDONLY, int mode=0666, __7_ string encoding) |
Create and open a File object in the current directory of the Dir object. | |
__7_ string | path () |
Returns the path of the Dir object or NOTHING if no path is set. | |
bool | removeFile (string file) |
Remove the file with the given name in the Dir object's directory. | |
nothing | rmdir (string subdir) |
Removes a direct subdirectory from the Dir object's current path. | |
list< auto > | stat () |
Returns a list of file status information for the current directory. | |
hash< FilesystemInfo > | statvfs () |
Returns a FilesystemInfo hash for the current directory. | |
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.
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 |
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) |
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) |
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) |
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) |
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) |
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.
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) |
list< auto > Qore::Dir::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.
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 |
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 , |
||
__7_ 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 |
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) |
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) |
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) |