MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 1 | SYNOPSIS |
| 2 | #include <files.h> |
| 3 | |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 4 | mixed * get_dir(string str) |
| 5 | mixed * get_dir(string str, int mask) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 6 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 7 | DESCRIPTION |
| 8 | This function takes a path as argument and returns an array of file |
| 9 | names and attributes in that directory. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 10 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 11 | Returns 0 if the directory to search in does not exist. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 12 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 13 | The filename part of the path may contain '*' or '?' as wildcards: |
| 14 | every '*' matches an arbitrary amount of characters (or just itself), |
| 15 | a '?' matches any character. Thus get_dir("/path/*") would return an |
| 16 | alphabetically sorted array of all files in directory "/path", or |
| 17 | just ({ "/path/*" }) if this file happens to exist. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 18 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 19 | To query the content of a directory, use the directory name with a |
| 20 | trailing '/' or '/.', for example get_dir("/path/."). Use the |
| 21 | directory name as it is to get information about the directory itself. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 22 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 23 | The optional second argument mask can be used to get |
| 24 | information about the specified files. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 25 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 26 | GETDIR_EMPTY (0x00) get_dir returns an empty array (not very |
| 27 | useful). |
| 28 | GETDIR_NAMES (0x01) put the alphabetically sorted file names into |
| 29 | the returned array. |
| 30 | GETDIR_SIZES (0x02) put the file sizes unsorted into the returned |
| 31 | array. directories have size FSIZE_DIR (-2). |
| 32 | GETDIR_DATES (0x04) put the file modification dates (in seconds |
| 33 | since 01/01/1970) unsorted into the |
| 34 | returned array. |
| 35 | GETDIR_ACCESS (0x40) put the file access dates unsorted into |
| 36 | the returned array. |
| 37 | GETDIR_MODES (0x80) put the unix file modes unsorted into |
| 38 | the returned array. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 39 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 40 | GETDIR_ALL (0xDF) Return all. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 41 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 42 | GETDIR_PATH (0x10) if this mask bit is set, the filenames with |
| 43 | the full path will be returned |
| 44 | (GETDIR_NAMES is implied). |
| 45 | GETDIR_UNSORTED (0x20) if this mask bit is set, the result of will |
| 46 | _not_ be sorted. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 47 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 48 | Note: You should use GETDIR_NAMES|GETDIR_UNSORTED to get the entries |
| 49 | in the same order as with GETDIR_SIZES and GETDIR_DATES. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 50 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 51 | The values of mask can be added together. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 52 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 53 | NOTES |
| 54 | The path argument to this efun is processed by valid_read() in the |
| 55 | mudlib master before being used. The mudlib may normalize this path |
| 56 | (e.g. strip leading or trailing "/") and this may lead to expected |
| 57 | results (e.g. get_dir("/dir/", ...) not returning the contents |
| 58 | of /dir/). |
| 59 | COMPAT mode: GETDIR_PATH will return the paths without leading /. |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 60 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 61 | EXAMPLES |
| 62 | function returns |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 63 | ------------------------------------------------------------------- |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 64 | get_dir("/obj/.") all files contained in directory /obj. |
| 65 | get_dir("/obj/") the same as get_dir("/obj/") |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 66 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 67 | get_dir("/obj/sword.c") ({ "sword.c" }) if /obj/sword.c |
| 68 | exists (it may be a file or a |
| 69 | directory), otherwise ({ }) if |
| 70 | /obj is a directory, |
| 71 | otherwise 0. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 72 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 73 | get_dir("/obj/*") ({ "*" }) if * exists. |
| 74 | otherwise and normally an |
| 75 | alphabetically sorted array with all |
| 76 | names of files and directories in |
| 77 | /obj if /obj is a directory, |
| 78 | otherwise 0. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 79 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 80 | get_dir("/obj/sword.c", GETDIR_SIZES) ({ <size of /obj/sword.c> }) |
| 81 | if that file exists. |
| 82 | get_dir("/obj/.", GETDIR_NAMES) the same as get_dir("/obj/."). |
| 83 | get_dir("/obj/.", GETDIR_SIZES) an array with the sizes of the files |
| 84 | in /obj, not sorted by names. |
| 85 | get_dir("/obj/.", GETDIR_NAMES|GETDIR_SIZES|GETDIR_DATES) or shorter |
| 86 | get_dir("/obj/.", GETDIR_ALL) an one-dimensional array that |
| 87 | contains for each file in /obj its |
| 88 | name, its size and its modification |
| 89 | date, sorted by names, for example |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 90 | ({ |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 91 | "axe.c" , 927, 994539583, |
| 92 | "sword.c", 1283, 998153903, |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 93 | }). |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 94 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 95 | get_dir("/obj/sword.c", GETDIR_NAMES|GETDIR_PATH) |
| 96 | ({ "/obj/sword.c" }) if applicable. |
| 97 | get_dir("/obj/sword.c", GETDIR_PATH) Short form of the same query. |
| 98 | |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 99 | |
| 100 | transpose_array(({ get_dir(str, GETDIR_NAMES|GETDIR_UNSORTED) |
| 101 | , get_dir(str, GETDIR_SIZES) |
| 102 | , get_dir(str, GETDIR_DATES) })); |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 103 | This returns an array of arrays, with filename, size and |
| 104 | filetime as elements, not sorted by names, for example |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 105 | ({ |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 106 | ({ "sword.c", 1283, 998153903 }), |
| 107 | ({ "axe.c" , 927, 994539583 }), |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 108 | }). |
| 109 | |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 110 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 111 | HISTORY |
| 112 | LDMud 3.2.9 added GETDIR_PATH. |
| 113 | LDMud 3.2.11/3.3.648 added GETDIR_ACCESS and GETDIR_MODES. |
| 114 | |
| 115 | SEE ALSO |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 116 | mkdir(E), rmdir(E), file_size(E), write_file(E), write_bytes(E), |
| 117 | read_file(E), read_bytes(E) |