Simple yet Useful File Functions

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
LuaWeaver
Party member
Posts: 183
Joined: Wed Mar 02, 2011 11:15 pm
Location: Ohio, USA

Simple yet Useful File Functions

Post by LuaWeaver »

Hello again, LOVErs. I've made a few functions that work for Windows only that help with files : allowing you to save them outside of the normal save directory! I know people have used this before, but I made a few handy functions, called mkdir and mkfile.

http://pastebin.com/jqETiCvD

Remember, Windows only. I'll work on a Mac and a Linux (Korn and Bash shell) version later, once I figure out how to use the terminal on those... since I only work with Windows, I don't know much about those. :death:

mkdir(parentDir, dirName) -- Creates a directory of the name dirName inside the directory parentDir.
mkfile(parentDir, fileName, fileContents) -- Creates a file of the name fileName containing the contents fileContents. fileContents supports newlines, it should be used with long strings.

getUser() -- shorthand for love.filesystem.getUserDirectory()
getSave() -- shorthand for love.filesystem.getSaveDirectory()

Example code:

Code: Select all

function love.load()
   mkdir(getUser().."\\Desktop","love2Ddir")
   mkfile(getUser().."\\Desktop\\love2Ddir","example.txt",[[
This is a test message.
Hello from Love2D!]])
end
Demo :
fileFuncs.love
(868 Bytes) Downloaded 80 times
"your actions cause me to infer your ego is the size of three houses" -finley
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 45 guests