Advertisement
EarthwyrmJim

delete

Apr 23rd, 2013
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.31 KB | None | 0 0
  1. term.clear()
  2. term.setCursorPos(1,1)
  3. os.loadAPI("ocs/apis/sensor")
  4. local a = peripheral.wrap("right")
  5. local s = sensor.wrap("left")
  6. local chest = s.getTargetDetails("0,1,0")
  7. local done = false
  8. local addedItems = {}
  9.  
  10. local function copyFile(fileR, fileW)
  11.         readFile = fs.open(fileR,"r")
  12.         writeFile = fs.open(fileW,"w")
  13.         while true do
  14.                 local lineRead = readFile.readLine()
  15.                 if lineRead == nil then
  16.                         break
  17.                 end
  18.                 local lineWritten = writeFile.writeLine(lineRead)              
  19.         end
  20.         readFile.close()
  21.     writeFile.close()
  22. end
  23.  
  24. local function deleteLine(fileR, fileW, item)
  25.         readFile = fs.open(fileR,"r")
  26.         writeFile = fs.open(fileW,"w")
  27.         while true do
  28.                 local lineRead = readFile.readLine()
  29.                 if lineRead == nil then
  30.                         break
  31.                 end
  32.         if not string.match(lineRead, item) then
  33.                     local lineWritten = writeFile.writeLine(lineRead)            
  34.             else
  35.             print(item.." was removed from list.")
  36.         end
  37.     end
  38.         readFile.close()
  39.     writeFile.close()
  40. end
  41.  
  42. copyFile("ID.txt", "ID")
  43. print("Item to delete: ")
  44. local itemToDelete = read()
  45. deleteLine("ID","ID.txt", itemToDelete)
  46. fs.delete("ID")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement