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(directory_string
)
chdir("/usr/share");
Not available with PO_NO_FILESYSTEM
Table 3.256. Arguments and Return Values for chdir()
Argument Type | Return Type | Description |
---|---|---|
String | Integer | Changes the current working directory. Returns 0 if successful. |
Table 3.257. Exceptions Thrown by chdir()
err | desc |
---|---|
| The string for the new directory was missing from the call. |
Changes the mode of a file.
chmod(filename, mode
)
chmod("/bin/login", 0755);
Not available with PO_NO_FILESYSTEM
Table 3.258. Arguments and Return Values for chmod()
Argument Type | Return Type | Description |
---|---|---|
String, Integer | Integer | Sets the mode of the given file to the integer passed. Returns 0 if successful. |
Table 3.259. 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(filepath, user_id, group_id
)
chown("/bin/login", 0, 0);
Not available with PO_NO_FILESYSTEM
Table 3.260. Arguments and Return Values for chown()
Argument Type | Return Type | Description |
---|---|---|
String, Integer, Integer | Integer | Changes the owner and group of the file passed. Returns 0 if successful. |
Table 3.261. Exceptions Thrown by chown()
err | desc |
---|---|
| Expecting a string as the first argument. |
Returns a string giving the current working directory.
getcwd()
my $cwd = getcwd();
Not available with PO_NO_FILESYSTEM
Table 3.262. Arguments and Return Values for getcwd()
Argument Type | Return Type | Description |
---|---|---|
n/a | String | Returns the complete path of the current working directory as a string. |
Returns a hash of filesystem 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).
hlstat(pathname
)
$type = hlstat("/bin/sh").type; # returns "REGULAR"
Not available with PO_NO_FILESYSTEM
Table 3.264. 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 |
| blocks allocated for the file |
| a string indicating the type of file: 'BLOCK-DEVICE', 'DIRECTORY', 'CHARACTER-DEVICE', 'FIFO', 'SYMBOLIC-LINK', 'SOCKET', 'CHARACTER-DEVICE', 'REGULAR', 'UNKNOWN' |
This function does not throw any exceptions.
Returns a hash of filesystem values for the file passed; symbolic links are followed; see hlstat() to retrieve information about a symbolic link.
hstat(pathname
)
$type = hstat("/bin/sh").type; # returns "REGULAR"
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.
is_bdev(path
)
$bool = is_bdev("/dev/sda");
Not available with PO_NO_FILESYSTEM
Table 3.266. Arguments and Return Values for is_bdev()
Argument Type |
Return Type |
Description |
---|---|---|
Path |
Boolean |
Returns True if the string passed identifies a block device file on the filesystem. |
Returns True if the string passed identifies a character device file on the filesystem.
is_cdev(path
)
$bool = is_cdev("/dev/tty");
Not available with PO_NO_FILESYSTEM
Table 3.267. Arguments and Return Values for is_cdev()
Argument Type |
Return Type |
Description |
---|---|---|
Path |
Boolean |
Returns True if the string passed identifies a character device file on the filesystem. |
Returns True if the string passed identifies a device file (either block or character) on the filesystem.
is_dev(path
)
$bool = is_dev("/dev/sda");
Not available with PO_NO_FILESYSTEM
Table 3.268. Arguments and Return Values for is_dev()
Argument Type |
Return Type |
Description |
---|---|---|
Path |
Boolean |
Returns True if the string passed identifies a device file (either block or character) on the filesystem. |
Returns True if the string passed identifies a directory on the filesystem.
is_dir(path
)
$bool = is_dir("/usr/share");
Not available with PO_NO_FILESYSTEM
Table 3.269. Arguments and Return Values for is_dir()
Argument Type |
Return Type |
Description |
---|---|---|
Path |
Boolean |
Returns True if the string passed identifies a directory on the filesystem. |
Returns True if the string passed identifies an executable file.
is_executable(path
)
$bool = is_executable("/bin/sh");
Not available with PO_NO_FILESYSTEM
Table 3.270. Arguments and Return Values for is_executable()
Argument Type |
Return Type |
Description |
---|---|---|
Path |
Boolean |
Returns True if the string passed identifies an executable file. |
Returns True if the string passed identifies a regular file on the filesystem.
is_file(path
)
$bool = is_file("/etc/hosts");
Not available with PO_NO_FILESYSTEM
Table 3.271. Arguments and Return Values for is_file()
Argument Type |
Return Type |
Description |
---|---|---|
Path |
Boolean |
Returns True if the string passed identifies a regular file on the filesystem. |
Returns True if the string passed identifies a symbolic link on the filesystem.
is_link(path
)
$bool = is_link("/bin/sh");
Not available with PO_NO_FILESYSTEM
Table 3.272. Arguments and Return Values for is_link()
Argument Type |
Return Type |
Description |
---|---|---|
Path |
Boolean |
Returns True if the string passed identifies a symbolic link on the filesystem. |
Returns True if the string passed identifies a pipe (FIFO) on the filesystem.
is_pipe(path
)
$bool = is_pipe("/bin/sh");
Not available with PO_NO_FILESYSTEM
Table 3.273. Arguments and Return Values for is_pipe()
Argument Type |
Return Type |
Description |
---|---|---|
Path |
Boolean |
Returns True if the string passed identifies a pipe (FIFO) on the filesystem. |
Returns True if the string passed identifies a file readable by the current user.
is_readable(path
)
$bool = is_readable("/etc/hosts");
Not available with PO_NO_FILESYSTEM
Table 3.274. Arguments and Return Values for is_readable()
Argument Type |
Return Type |
Description |
---|---|---|
Path |
Boolean |
Returns True if the string passed identifies a file readable by the current user. |
Returns True if the string passed identifies a socket on the filesystem.
is_socket(path
)
$bool = is_socket("/tmp/X0");
Not available with PO_NO_FILESYSTEM
Table 3.275. Arguments and Return Values for is_socket()
Argument Type |
Return Type |
Description |
---|---|---|
Path |
Boolean |
Returns True if the string passed identifies a socket on the filesystem. |
Returns True if the string passed identifies a file writable by the current user.
is_writeable(path
)
$bool = is_writeable("/etc/hosts");
Not available with PO_NO_FILESYSTEM
Table 3.276. Arguments and Return Values for is_writeable()
Argument Type |
Return Type |
Description |
---|---|---|
Path |
Boolean |
Returns True if the string passed identifies a file writable by the current user. |
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(filepath, user_id, group_id
)
lchown("/bin/login", 0, 0);
Not available with PO_NO_FILESYSTEM
Table 3.277. Arguments and Return Values for lchown()
Argument Type | Return Type | Description |
---|---|---|
String, Integer, Integer | Integer | Changes the owner and group of the file passed. Returns 0 if successful. |
Table 3.278. Exceptions Thrown by lchown()
err | desc |
---|---|
| Expecting a string as the first argument. |
Returns a list of filesystem 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.
lstat(pathname
)
$list = lstat(("/bin/sh");
Not available with PO_NO_FILESYSTEM
Table 3.279. Arguments and Return Values for lstat()
Argument Type | Return Type | Description |
---|---|---|
String | List | Returns a list of filesystem values for the file passed. See Stat List for a description of the list returned by this function. |
This function does not throw any exceptions.
Creates a directory, optionally specifying the mode.
mkdir(string_name, [mode]
)
mkdir("/tmp/newdir", 0755);
Not available with PO_NO_FILESYSTEM
Table 3.280. Arguments and Return Values for mkdir()
Argument Type | Return Type | Description |
---|---|---|
String, [Integer] | Integer | Creates a directory with the specified name. If the mode parameter is not sent, then 0777 is used by default (which is AND'ed with the umask). Returns 0 if no error occurred. |
Table 3.281. Exceptions Thrown by mkdir()
err | desc |
---|---|
| Missing directory name for the mkdir() call. |
Creates a named pipe file with an optional file mode (default = 0600).
mkfifo(filename, [mode]
)
mkfifo("/tmp/pipe");
Not available with PO_NO_FILESYSTEM
Table 3.282. Arguments and Return Values for mkfifo()
Argument Type |
Return Type |
Description |
---|---|---|
String, [Integer] |
Integer |
Creates a named pipe with the supplied path and optional mode. If |
This function does not throw any exceptions.
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(old_path, new_path
)
rename("/tmp/temp_file", "/home/test/test_file.txt");
Not available with PO_NO_FILESYSTEM
Table 3.283. Arguments and Return Values for rename()
Argument Type | Return Type | Description |
---|---|---|
String, String | n/a | Renames (or moves) the file ior directory indentified by |
Table 3.284. Exceptions Thrown by rename()
err | desc |
---|---|
| Missing arguments or a system error occured. |
Removes a directory.
rmdir(path
)
rmdir("/tmp/newdir");
Not available with PO_NO_FILESYSTEM
Table 3.285. Arguments and Return Values for rmdir()
Argument Type | Return Type | Description |
---|---|---|
String | Integer | Removes an empty directory. Returns 0 if no error occurred. |
Table 3.286. Exceptions Thrown by rmdir()
err | desc |
---|---|
| Missing directory name for the |
Sets the file creation mask for the process.
umask(mode
)
umask(0777);
Not available with PO_NO_FILESYSTEM
Table 3.287. Arguments and Return Values for umask()
Argument Type | Return Type | Description |
---|---|---|
Integer | Integer | Sets the file creation mask for the process, returns 0 for success. If no argument is passed, no action is taken, and the function returns NOTHING. |
This function does not throw any exceptions.
Deletes a file and returns 0 for success.
unlink(file
)
unlink("/tmp/tmp_file");
Not available with PO_NO_FILESYSTEM
Table 3.288. Arguments and Return Values for unlink()
Argument Type | Return Type | Description |
---|---|---|
String | Integer | Deletes a file and returns 0 for success. |
This function does not throw any exceptions.