SDL 3.0
|
#include <SDL3/SDL_stdinc.h>
#include <SDL3/SDL_error.h>
#include <SDL3/SDL_begin_code.h>
#include <SDL3/SDL_close_code.h>
Go to the source code of this file.
Data Structures | |
struct | SDL_PathInfo |
Macros | |
#define | SDL_GLOB_CASEINSENSITIVE (1u << 0) |
Typedefs | |
typedef Uint32 | SDL_GlobFlags |
typedef int(* | SDL_EnumerateDirectoryCallback) (void *userdata, const char *dirname, const char *fname) |
Functions | |
const char * | SDL_GetBasePath (void) |
char * | SDL_GetPrefPath (const char *org, const char *app) |
const char * | SDL_GetUserFolder (SDL_Folder folder) |
SDL_bool | SDL_CreateDirectory (const char *path) |
SDL_bool | SDL_EnumerateDirectory (const char *path, SDL_EnumerateDirectoryCallback callback, void *userdata) |
SDL_bool | SDL_RemovePath (const char *path) |
SDL_bool | SDL_RenamePath (const char *oldpath, const char *newpath) |
SDL_bool | SDL_CopyFile (const char *oldpath, const char *newpath) |
SDL_bool | SDL_GetPathInfo (const char *path, SDL_PathInfo *info) |
char ** | SDL_GlobDirectory (const char *path, const char *pattern, SDL_GlobFlags flags, int *count) |
#define SDL_GLOB_CASEINSENSITIVE (1u << 0) |
Definition at line 263 of file SDL_filesystem.h.
typedef int(* SDL_EnumerateDirectoryCallback) (void *userdata, const char *dirname, const char *fname) |
Definition at line 280 of file SDL_filesystem.h.
typedef Uint32 SDL_GlobFlags |
Flags for path matching
Definition at line 261 of file SDL_filesystem.h.
enum SDL_Folder |
The type of the OS-provided default folder for a specific purpose.
Note that the Trash folder isn't included here, because trashing files usually involves extra OS-specific functionality to remember the file's original location.
The folders supported per platform are:
Windows | WinRT/UWP | macOS/iOS | tvOS | Unix (XDG) | Haiku | Emscripten | |
---|---|---|---|---|---|---|---|
HOME | X | X | X | X | X | X | |
DESKTOP | X | X | X | X | X | ||
DOCUMENTS | X | X | X | X | |||
DOWNLOADS | Vista+ | X | X | X | |||
MUSIC | X | X | X | X | |||
PICTURES | X | X | X | X | |||
PUBLICSHARE | X | X | |||||
SAVEDGAMES | Vista+ | ||||||
SCREENSHOTS | Vista+ | X | |||||
TEMPLATES | X | X | X | X | |||
VIDEOS | X | X | X* | X |
Note that on macOS/iOS, the Videos folder is called "Movies".
Definition at line 166 of file SDL_filesystem.h.
enum SDL_PathType |
Definition at line 236 of file SDL_filesystem.h.
|
extern |
Copy a file.
oldpath | the old path. |
newpath | the new path. |
|
extern |
Create a directory.
path | the path of the directory to create. |
|
extern |
Enumerate a directory through a callback function.
This function provides every directory entry through an app-provided callback, called once for each directory entry, until all results have been provided or the callback returns <= 0.
path | the path of the directory to enumerate. |
callback | a function that is called for each entry in the directory. |
userdata | a pointer that is passed to callback . |
|
extern |
SDL Filesystem API. Get the directory where the application was run from.
SDL caches the result of this call internally, but the first call to this function is not necessarily fast, so plan accordingly.
macOS and iOS Specific Functionality: If the application is in a ".app" bundle, this function returns the Resource directory (e.g. MyApp.app/Contents/Resources/). This behaviour can be overridden by adding a property to the Info.plist file. Adding a string key with the name SDL_FILESYSTEM_BASE_DIR_TYPE with a supported value will change the behaviour.
Supported values for the SDL_FILESYSTEM_BASE_DIR_TYPE property (Given an application in /Applications/SDLApp/MyApp.app):
resource
: bundle resource directory (the default). For example: /Applications/SDLApp/MyApp.app/Contents/Resources
bundle
: the Bundle directory. For example: /Applications/SDLApp/MyApp.app/
parent
: the containing directory of the bundle. For example: /Applications/SDLApp/
Nintendo 3DS Specific Functionality: This function returns "romfs" directory of the application as it is uncommon to store resources outside the executable. As such it is not a writable directory.
The returned path is guaranteed to end with a path separator ('\' on Windows, '/' on most other platforms).
|
extern |
Get information about a filesystem path.
path | the path to query. |
info | a pointer filled in with information about the path, or NULL to check for the existence of a file. |
|
extern |
Get the user-and-app-specific path where files can be written.
Get the "pref dir". This is meant to be where users can write personal files (preferences and save games, etc) that are specific to your application. This directory is unique per user, per application.
This function will decide the appropriate location in the native filesystem, create the directory if necessary, and return a string of the absolute path to the directory in UTF-8 encoding.
On Windows, the string might look like:
C:\\Users\\bob\\AppData\\Roaming\\My Company\\My Program Name\\
On Linux, the string might look like:
/home/bob/.local/share/My Program Name/
On macOS, the string might look like:
/Users/bob/Library/Application Support/My Program Name/
You should assume the path returned by this function is the only safe place to write files (and that SDL_GetBasePath(), while it might be writable, or even the parent of the returned path, isn't where you should be writing things).
Both the org and app strings may become part of a directory name, so please follow these rules:
The returned path is guaranteed to end with a path separator ('\' on Windows, '/' on most other platforms).
org | the name of your organization. |
app | the name of your application. |
|
extern |
Finds the most suitable user folder for a specific purpose.
Many OSes provide certain standard folders for certain purposes, such as storing pictures, music or videos for a certain user. This function gives the path for many of those special locations.
This function is specifically for user folders, which are meant for the user to access and manage. For application-specific folders, meant to hold data for the application to manage, see SDL_GetBasePath() and SDL_GetPrefPath().
The returned path is guaranteed to end with a path separator ('\' on Windows, '/' on most other platforms).
If NULL is returned, the error may be obtained with SDL_GetError().
folder | the type of folder to find. |
|
extern |
Enumerate a directory tree, filtered by pattern, and return a list.
Files are filtered out if they don't match the string in pattern
, which may contain wildcard characters '*' (match everything) and '?' (match one character). If pattern is NULL, no filtering is done and all results are returned. Subdirectories are permitted, and are specified with a path separator of '/'. Wildcard characters '*' and '?' never match a path separator.
flags
may be set to SDL_GLOB_CASEINSENSITIVE to make the pattern matching case-insensitive.
The returned array is always NULL-terminated, for your iterating convenience, but if count
is non-NULL, on return it will contain the number of items in the array, not counting the NULL terminator.
path | the path of the directory to enumerate. |
pattern | the pattern that files in the directory must match. Can be NULL. |
flags | SDL_GLOB_* bitflags that affect this search. |
count | on return, will be set to the number of items in the returned array. Can be NULL. |
\threadsafety It is safe to call this function from any thread.
|
extern |
Remove a file or an empty directory.
path | the path of the directory to enumerate. |
|
extern |
Rename a file or directory.
oldpath | the old path. |
newpath | the new path. |