how use the love.filesystem

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
sky2046
Prole
Posts: 2
Joined: Fri Jul 27, 2018 3:18 am

how use the love.filesystem

Post by sky2046 »

I recently encountered some difficulties when i create a log file and directory.
why did i call the function[love.filesystem.createDirectory] failed, the following show code.

Code: Select all

logDir = "./log"
logPath = "./log/sad.log"

function love.load()
   loadStatus, errString = initLog()
end

function love.draw()
    if (false == loadStatus) then
        love.graphics.printf("progress load fail:\r\n \t" .. errString, 0, 0, 1024, "left")
    end
    
end

function love.update(dt)

end

function initLog()
    cwd = love.filesystem.getWorkingDirectory()
    if ("/" ~= string.sub(cwd, -1, -1)) then
        cwd = cwd .. "/"
    end
    
    if ("./" == string.sub(logDir, 1, 2)) then
        logDir = cwd .. string.sub(logDir, 3)
    end
  
    if (nil == love.filesystem.getInfo(logDir, "directory")) then
        if (false == love.filesystem.createDirectory(logDir)) then
            return false, "can not create directory[" .. logDir .. " ]"
        end
    end
    
    
    if ("./" == string.sub(logPath, 1, 2)) then
        logPath = cwd .. string.sub(logPath, 3)
    end

    if (nil == love.filesystem.getInfo(logPath, "file")) then
        logFile = love.filesystem.newFile(logPath)
        if (false == logFile:open("r")) then
        	return false, "can not create file[" .. logPath .. " ]"
        end
    end
end
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: how use the love.filesystem

Post by grump »

You can only write to the save directory. It is different from the working directory, and the only control you have over it is setting its name (not path/location) through the game's identity. This is all explained here.
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests