love.filesystem.getRealDirectory

love.filesystem.getRealDirectory

Available since LÖVE 0.9.2
This function is not supported in earlier versions.

Gets the platform-specific absolute path of the directory containing a filepath.

This can be used to determine whether a file is inside the save directory or the game's source .love.

Function

Synopsis

realdir = love.filesystem.getRealDirectory( filepath )

Arguments

string filepath
The filepath to get the directory of.

Returns

string realdir
The platform-specific full path of the directory containing the filepath.

Notes

This function returns the directory containing the given file path, rather than file. For example, if the file screenshot1.png exists in a directory called screenshots in the game's save directory, love.filesystem.getRealDirectory("screenshots/screenshot1.png") will return the same value as love.filesystem.getSaveDirectory.

Examples

-- Get all files in the "levels" folder.
-- There might be a "levels" folder in both the save directory and the game's source,
-- in which case this will get all files in both.
local filepaths = love.filesystem.getDirectoryItems("levels")
 
for i, filename in ipairs(filepaths) do
    -- For each filename, check whether it's in the save directory or not.
    local path = "levels/"..filename
    if love.filesystem.getRealDirectory(path) == love.filesystem.getSaveDirectory() then
        -- This file is in the save directory.
    end
end

See Also

doc_love
2017-03-21 15:46:10
Comments
Leave a Comment

Please login to continue.