3.3. Filesystem utilities
Those are a few function that cannot be easily implemented in a portable way in C/C++. They have no python wrapper since python provides its own builtin functions. All those functions return false if an error occured.
Create a directory
static bool TCODSystem::createDirectory(const char *path)
bool TCOD_sys_create_directory(const char *path)
Parameter | Description |
---|---|
path | Directory path. The immediate father directory ( |
Delete an empty directory
static bool TCODSystem::deleteDirectory(const char *path)
bool TCOD_sys_delete_directory(const char *path)
Parameter | Description |
---|---|
path | directory path. This directory must exist, be writable and empty |
Delete a file
static bool TCODSystem::deleteFile(const char *path)
bool TCOD_sys_delete_file(const char *path)
Parameter | Description |
---|---|
path | File path. This file must exist and be writable. |
Check if a path is a directory
static bool TCODSystem::isDirectory(const char *path)
bool TCOD_sys_is_directory(const char *path)
Parameter | Description |
---|---|
path | a path to check |
List files in a directory
To get the list of entries in a directory (including sub-directories, except . and ..).
The returned list is allocated by the function and must be deleted by you. All the const char * inside must be also freed with TCODList::clearAndDelete.
static TCODList TCODSystem::getDirectoryContent(const char *path, const char *pattern)
TCOD_list_t TCOD_sys_get_directory_content(const char *path)
Parameter | Description |
---|---|
path | a directory |
pattern | If NULL or empty, returns all directory entries. Else returns only entries matching the pattern. The pattern is NOT a regular expression. It can only handle one '*' wildcard. Examples : *.png, saveGame*, font*.png |
Check if a given file exists
In order to check whether a given file exists in the filesystem. Useful for detecting errors caused by missing files.
static bool TCODSystem::fileExists(const char *filename, ...)
bool TCOD_sys_file_exists(const char * filename, ...)
Parameter | Description |
---|---|
filename | the file name, using printf-like formatting |
... | optional arguments for filename formatting |
Example:
if (!TCODSystem::fileExists("myfile.%s","txt")) {
fprintf(stderr,"no such file!");
}
if (!TCOD_sys_file_exists("myfile.%s","txt")) {
fprintf(stderr,"no such file!");
}