Advertisement
LuaWeaver

Love2D File Functions

Nov 29th, 2012
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.98 KB | None | 0 0
  1. local shell=os.execute
  2. local lfs=love.filesystem
  3.  
  4. function mkdir(targetDir,dirName)
  5.     local bat=lfs.newFile('temp.bat')
  6.     source="@echo off\ncd "..targetDir.."\n".."mkdir "..dirName
  7.     source:gsub("\n","\r\n")
  8.     bat:open('w')
  9.     bat:write(source)
  10.     bat:close()
  11.     shell(lfs.getSaveDirectory().."\\"..'temp')
  12.     lfs.remove('temp.bat')
  13. end
  14.  
  15. function mkfile(targetDir,dirName,fileContents)
  16.     local bat=lfs.newFile('temp.bat')
  17.     local _,count=fileContents:gsub("\n",'')
  18.     source="@echo off\ncd "..targetDir.."\n"
  19.     local q=0
  20.     for str in fileContents:gmatch("[^\n]+") do
  21.         q=q+1
  22.         local appendOrWrite=" >> "
  23.         if q==1 then
  24.             appendOrWrite=" > "
  25.         end
  26.         source=source.."echo "..str:gsub("\n",'')..appendOrWrite..dirName.."\n"
  27.     end
  28.     source:gsub("\n","\r\n")
  29.     bat:open('w')
  30.     bat:write(source)
  31.     bat:close()
  32.     shell(lfs.getSaveDirectory().."\\"..'temp')
  33.     lfs.remove('temp.bat')
  34. end
  35.  
  36. function userDir()
  37.     return lfs.getUserDirectory()
  38. end
  39.  
  40. function saveDir()
  41.     return lfs.getSaveDirectory()
  42. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement