File Utilities

The XPLMUtilities file APIs provide some basic file and path functions for use with X-Plane.

Directory Separators

The XPLM has two modes it can work in:

While legacy OS paths are the default, we strongly encourage you to opt in to native paths using the XPLMEnableFeature API.

Full and Relative Paths

Some of these APIs use full paths, but others use paths relative to the user's X-Plane installation. This is documented on a per-API basis.


XPLMDataFileType

enum XPLM200

These enums define types of data files you can load or unload using the SDK.

Name Value Description
xplm_DataFile_Situation 1 A situation (.sit) file, which starts off a flight in a given configuration.
xplm_DataFile_ReplayMovie 2 A situation movie (.smo) file, which replays a past flight.

XPLMGetSystemPath

function

This function returns the full path to the X-System folder. Note that this is a directory path, so it ends in a trailing : or / .

The buffer you pass should be at least 512 characters long. The path is returned using the current native or OS path conventions.

XPLM_API void       XPLMGetSystemPath(
                         char *               outSystemPath
                    );

XPLMGetPrefsPath

function

This routine returns a full path to a file that is within X-Plane's preferences directory. (You should remove the file name back to the last directory separator to get the preferences directory using XPLMExtractFileAndPath).

The buffer you pass should be at least 512 characters long. The path is returned using the current native or OS path conventions.

XPLM_API void       XPLMGetPrefsPath(
                         char *               outPrefsPath
                    );

XPLMGetDirectorySeparator

function

This routine returns a string with one char and a null terminator that is the directory separator for the current platform. This allows you to write code that concatenates directory paths without having to #ifdef for platform. The character returned will reflect the current file path mode.

XPLM_API const char *XPLMGetDirectorySeparator(void);

XPLMExtractFileAndPath

function

Given a full path to a file, this routine separates the path from the file. If the path is a partial directory (e.g. ends in : or / ) the trailing directory separator is removed. This routine works in-place; a pointer to the file part of the buffer is returned; the original buffer still starts with the path and is null terminated with no trailing separator.

XPLM_API char *     XPLMExtractFileAndPath(
                         char *               inFullPath
                    );

XPLMGetDirectoryContents

function

This routine returns a list of files in a directory (specified by a full path, no trailing : or / ). The output is returned as a list of NULL terminated strings. An index array (if specified) is filled with pointers into the strings. The last file is indicated by a zero-length string (and NULL in the indices). This routine will return true if you had capacity for all files or false if you did not. You can also skip a given number of files.

Return value: 1 if all info could be returned, 0 if there was a buffer overrun.

WARNING: Before X-Plane 7 this routine did not properly iterate through directories. If X-Plane 6 compatibility is needed, use your own code to iterate directories.

XPLM_API int        XPLMGetDirectoryContents(
                         const char *         inDirectoryPath,
                         int                  inFirstReturn,
                         char *               outFileNames,
                         int                  inFileNameBufSize,
                         char * *             outIndices,    /* Can be NULL */
                         int                  inIndexCount,
                         int *                outTotalFiles,    /* Can be NULL */
                         int *                outReturnedFiles    /* Can be NULL */
                    );

XPLMLoadDataFile

function XPLM200

Loads a data file of a given type. Paths must be relative to the X-System folder. To clear the replay, pass a NULL file name (this is only valid with replay movies, not sit files).

XPLM_API int        XPLMLoadDataFile(
                         XPLMDataFileType     inFileType,
                         const char *         inFilePath    /* Can be NULL */
                    );

XPLMSaveDataFile

function XPLM200

Saves the current situation or replay; paths are relative to the X-System folder.

XPLM_API int        XPLMSaveDataFile(
                         XPLMDataFileType     inFileType,
                         const char *         inFilePath
                    );