Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- This is the file API
- -- I made this to make writing files n' stuff
- -- easier
- -- Chock500 - 22|12|12,016HE
- os.loadAPI("chockos/config")
- function writeFile(directory,name,contents)
- -- Simply input the directory of the new file,
- -- then put in the name and then what you want
- -- to put inside
- local file = io.open(directory.."/"..name,"w")
- file:write(contents)
- file:close()
- end
- function readFile(destination)
- -- This literally takes the destination of a file
- -- and returns its contents, that's it.
- local file = fs.open(destination,"r")
- contents = file.readAll()
- file.close()
- return contents
- end
- function listFiles(directory,x,y,pre)
- -- this lists files
- -- it prints them beginning at x,y
- -- point it at a directory
- -- pre can be any string or true
- -- when true, it prints a different prefix,
- -- depending on whether or not it is a directory
- pref = pre
- y = y - 1
- files = fs.list(directory)
- length = table.getn(files)
- listLoop = 1
- while listLoop <= length do
- term.setCursorPos(x,y+listLoop)
- if pre == true then
- if fs.isDir(directory..files[listLoop]) then
- pref = "[] "
- term.setTextColour(colours.lightBlue)
- else
- pref = ">> "
- term.setTextColor(colours.blue)
- end
- end
- print(pref..files[listLoop])
- listLoop = listLoop+1
- end
- term.setTextColour(config.defaultTextColour())
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement