The following functions return information about or are related to the filesystem. See the File class for a class enabling files to be created, read or written, and the Dir class allowing directories to be manipulated.
Changes the current working directory.
chdir("/usr/share");Not available with PO_NO_FILESYSTEM
Table 3.286. Exceptions Thrown by chdir()
err | desc |
|---|---|
| The string for the new directory was missing from the call. |
Changes the mode of a file.
chmod("/bin/login", 0755);Not available with PO_NO_FILESYSTEM
Table 3.288. Exceptions Thrown by chmod()
err | desc |
|---|---|
| Either the filename or the mode was missing from the call. |
Changes the user and group owners of a file, if the current user has permission to do so (normally only the superuser can change the user owner), follows symbolic links. For a version of this function that does not follow symbolic links, see the lchown() function.
chown("/bin/login", 0, 0);Not available with PO_NO_FILESYSTEM
Table 3.290. Exceptions Thrown by chown()
err | desc |
|---|---|
| This exception is thrown when the function is not available on the runtime platform; for maximum portability, check the constant |
Returns a string giving the current working directory or NOTHING if the current working directory could not be read.
See getcwd2() for a similar function that throws an exception if an error occurs instead.
my *string $cwd = getcwd();Not available with PO_NO_FILESYSTEM or PO_NO_EXTERNAL_INFO
Returns a string giving the current working directory; throws an exception if the current directory cannot be read.
See getcwd() for a similar function that returns NOTHING instead of throwing an exception if an error occurs.
my string $cwd = getcwd2();Not available with PO_NO_FILESYSTEM or PO_NO_EXTERNAL_INFO
Table 3.292. Arguments and Return Values for getcwd2()
Argument Type | Return Type | Description |
|---|---|---|
n/a | Returns the complete path of the current working directory as a string. |
Table 3.293. Exceptions Thrown by getcwd2()
err | desc |
|---|---|
| The operating system error is reported in the description string. |
Returns a hash of file status values for the file passed; symbolic links are not followed; information is returned about symbolic links (see hstat() for a version of this function that follows symbolic links).
See also File::hlstat() for a static method in the File class that throws an exception instead of returning NOTHING when errors occur.
my *string $type = hlstat("/bin/sh").type; # returns "REGULAR"Not available with PO_NO_FILESYSTEM
Table 3.294. Arguments and Return Values for hlstat()
Argument Type | Return Type | Description |
|---|---|---|
| Returns a hash of file status values for the file passed or NOTHING if the |
This function does not throw any exceptions.
Table 3.295. Stat Hash Description
Key | Value Description |
|---|---|
| device inode number the file is on |
| inode of the file |
| inode protection mode |
| number of hard links to this file |
| user ID of the owner |
| group ID of the owner |
| device type number |
| file size in bytes |
| last access time of the file |
| last modified time of the file |
| last change time of the file's inode |
| block size |
| a string indicating the type of file: 'BLOCK-DEVICE', 'DIRECTORY', 'CHARACTER-DEVICE', 'FIFO', 'SYMBOLIC-LINK', 'SOCKET', 'CHARACTER-DEVICE', 'REGULAR', 'UNKNOWN' |
| a string symbolizing the permissions of the file/dir/etc like that output by ls, for example: |
Returns a hash of file status values for the file passed; symbolic links are followed; see hlstat() to retrieve information about a symbolic link.
If any errors occur, NOTHING is returned and errno() can be used to retrieve the error number.
See also File::hstat() for a static method in the File class that throws an exception instead of returning NOTHING when errors occur.
my *hash $h = hstat("/bin/sh")Not available with PO_NO_FILESYSTEM
This function does not throw any exceptions.
Returns True if the string passed identifies a block device file on the filesystem.
$bool = is_bdev("/dev/sda");Not available with PO_NO_FILESYSTEM
Returns True if the string passed identifies a character device file on the filesystem.
$bool = is_cdev("/dev/tty");Not available with PO_NO_FILESYSTEM
Returns True if the string passed identifies a device file (either block or character) on the filesystem.
$bool = is_dev("/dev/sda");Not available with PO_NO_FILESYSTEM
Returns True if the string passed identifies a directory on the filesystem.
$bool = is_dir("/usr/share");Not available with PO_NO_FILESYSTEM
Returns True if the string passed identifies an executable file.
boolis_executable(string$path) (CONST)
$bool = is_executable("/bin/sh");Not available with PO_NO_FILESYSTEM
Table 3.302. Exceptions Thrown by is_executable()
err | desc |
|---|---|
| This exception is thrown when the function is not available; for maximum portability, check the constant |
Returns True if the string passed identifies a regular file on the filesystem.
$bool = is_file("/etc/hosts");Not available with PO_NO_FILESYSTEM
Returns True if the string passed identifies a symbolic link on the filesystem.
$bool = is_link("/bin/sh");Not available with PO_NO_FILESYSTEM
Returns True if the string passed identifies a pipe (FIFO) on the filesystem.
$bool = is_pipe("/bin/sh");Not available with PO_NO_FILESYSTEM
Returns True if the string passed identifies a file readable by the current user.
boolis_readable(string$path) (CONST)
$bool = is_readable("/etc/hosts");Not available with PO_NO_FILESYSTEM
Returns True if the string passed identifies a socket on the filesystem.
$bool = is_socket("/tmp/X0");Not available with PO_NO_FILESYSTEM
Table 3.308. Exceptions Thrown by is_socket()
err | desc |
|---|---|
| This exception is thrown when the function is not available; for maximum portability, check the constant |
Returns True if the string passed identifies a file writable by the current user.
boolis_writeable(string$path) (CONST)
$bool = is_writeable("/etc/hosts");Not available with PO_NO_FILESYSTEM
Changes the user and group owners of a file, if the current user has permission to do so (normally only the superuser can change the user owner), does not follow symbolic links. For a version of this function that follows symbolic links, see the chown() function.
lchown("/bin/login", 0, 0);Not available with PO_NO_FILESYSTEM
Table 3.311. Exceptions Thrown by lchown()
err | desc |
|---|---|
| This exception is thrown when the function is not available on the runtime platform; for maximum portability, check the constant |
Returns a list of file status values for the file or symbolic link passed. Does not follow symbolic links, but rather returns filesystem information for symbolic links. See also stat() for a version of this function that follows symbolic links, and hlstat() for a version of this function that returns a user-friendly hash instead of a list.
my *list $list = lstat("/bin/sh");Not available with PO_NO_FILESYSTEM
This function does not throw any exceptions.
Creates a directory, optionally specifying the mode.
mkdir("/tmp/newdir", 0755);Not available with PO_NO_FILESYSTEM
Creates a named pipe file with an optional file mode (default = 0600).
mkfifo("/tmp/pipe");Not available with PO_NO_FILESYSTEM
Table 3.315. Exceptions Thrown by mkfifo()
err | desc |
|---|---|
| This exception is thrown when the function is not available on the runtime platform; for maximum portability, check the constant |
Returns the target of a symbolic link; throws an exception if an error occurs (ex: file does not exist or is not a symbolic link).
my string $str = readlink("/tmp/symbolic_link");Not available with PO_NO_FILESYSTEM
Table 3.317. Exceptions Thrown by readlink()
err | desc |
|---|---|
| Invalid arguments or a system error occured (ex: file does not exist or is not a symbolic link). |
| This exception is thrown when the function is not available on the runtime platform; for maximum portability, check the constant |
Renames (or moves) files or directories. Note that for this call to function properly, the Qore process must have sufficient permissions and access to the given filesystem objects or paths to execute the rename operation.
This function does not return any value; if any errors occur, an exception is thrown.
rename("/tmp/temp_file", "/home/test/test_file.txt");Not available with PO_NO_FILESYSTEM
Table 3.319. Exceptions Thrown by rename()
err | desc |
|---|---|
| Invalid arguments or a system error occured. |
Removes a directory.
rmdir("/tmp/newdir");Not available with PO_NO_FILESYSTEM
Returns a list of file status values for the file passed, following any symbolic links. If any errors occur, NOTHING is returned and errno() can be used to retrieve the error number.
See also lstat() for a version of this function that does not follow symbolic links, and see hstat() for a version of this function that returns a user-friendly hash instead of a list.
See also File::stat() for a static method in the File class that throws an exception instead of returning NOTHING when errors occur.
$mode = stat($filepath)[2];
Not available with PO_NO_FILESYSTEM
This function does not throw any exceptions.
Table 3.322. Stat List Description
Position | Data Type | Description |
|---|---|---|
0 | device inode number the file is on | |
1 | inode of the file | |
2 | inode protection mode | |
3 | number of hard links to this file | |
4 | user ID of the owner | |
5 | group ID of the owner | |
6 | device type number | |
7 | file size in bytes | |
8 | last access time of the file | |
9 | last modified time of the file | |
10 | last change time of the file's inode | |
11 | block size | |
12 | blocks allocated for the file |
Returns a hash of filesystem status values for the file or directory path passed.
If any errors occur, NOTHING is returned and errno() can be used to retrieve the error number.
See also File::statvfs() for a static method in the File class that throws an exception instead of returning NOTHING when errors occur.
my *hash $h = statvfs("/tmp")Not available with PO_NO_FILESYSTEM
Table 3.323. Arguments and Return Values for statvfs()
Argument Type | Return Type | Description |
|---|---|---|
| Returns a hash of filesystem status values for the file or directory name passed or NOTHING if the |
Table 3.324. Exceptions Thrown by statvfs()
err | desc |
|---|---|
| This exception is thrown when the function is not available on the runtime platform; for maximum portability, check the constant |
Table 3.325. Filesystem Status Hash Description
Key | Value Description |
|---|---|
| The maximum length in mytes of file names on the filesystem |
| The filesystem ID; may not be set or meaningful on all filesystems/systems: see system documentation for |
| The size in bytes of the minimum allocation unit on the filesystem |
| The filesystem's block size |
| Flags describing mount options for the filesystem |
| The total number of inodes on the filesystem |
| The number of free inodes available to unpriviledged users |
| The total number of free indes available to priviledged users |
| The total number of blocks on the filesystem (capacity in bytes = bsize * blocks) |
| The number of free blocks available to unpriviledged users (bytes = bsize * bavail) |
| The total number of free indes available to priviledged users (bytes = bsize * bfree) |
There are no comments yet