Advertisement
XDemonic

API - FS

Oct 27th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.73 KB | None | 0 0
  1. local io = require("io")
  2. local fs = require("filesystem")
  3.  
  4. function ReadLine(Path, Line)
  5.     local Cur = 0
  6.     if (fs.exists(Path)) then
  7.         for LINE in io.lines(Path) do
  8.             Cur = Cur + 1
  9.             if (Cur == Line) then
  10.                 return LINE
  11.             end
  12.         end
  13.     end
  14.     return nil
  15. end
  16.  
  17. function WriteLine(Path, Line, Content)
  18.     local Lines = {}
  19.     if (fs.exists(Path)) then
  20.         for LINE in io.lines(Path) do
  21.             table.insert(Lines, LINE)
  22.         end
  23.     end
  24.         table.remove(Lines, Line)
  25.         table.insert(Lines, Line, Content)
  26.         local File = fs.open(Path..".tmp", "w")
  27.         for _, LINE in ipairs(Lines) do
  28.             print("Writing: "..LINE)
  29.             File:write(LINE.."\n")
  30.         end
  31.         File:close()
  32.         if (fs.exists(Path)) then
  33.             fs.remove(Path)
  34.         end
  35.         fs.rename(Path..".tmp", Path)
  36. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement