this is what I want too do..
usage: input -i [(Text)] [(File Name)]
the command makes a file and then it inputes the Text what you typed..
usage: input -i [(Text)] [(File Name)]
local function readLines(sPath)
local fHandle = fs.open(sPath, 'r')
if fHandle then
local tLines = {}
for sLine in fHandle.readLine do
tLines[#tLines+1] = sLine
end
fHandle.close()
return tLines
end
end
local function writeLines(sPath, tLines)
local fHandle = fs.open(sPath, 'w')
if fHandle then
fHandle.writeLine(table.concat(tLines, '\n'))
fHandle.close()
end
end
I believe this should create the file if it's not there.
fileContent = readLines("file")
-- this will be a table including all the lines from the file. Ignore it if you dont need to get information from the file.
writeContent = {[1] = "hello" [2] = "world"}
writeLines("file", writeContent)
function readLines(sPath)
local fHandle = fs.open(sPath, 'r')
if fHandle then
local tLines = {}
for sLine in fHandle.readLine do
tLines[#tLines+1] = sLine
end
fHandle.close()
return tLines
end
end
function writeLines(sPath, tLines)
local fHandle = fs.open(sPath, 'w')
if fHandle then
fHandle.writeLine(table.concat(tLines, '\n'))
fHandle.close()
end
end
function printUsage()
print("Usage: file [(OPTION)] [(File Name)]")
print("Usage: file -i [(File Name)] [(Text)]")
print(" ")
print("-find -- Is an option that finds a file.")
print(" ")
print("-o -- It shows the output of your file content.")
print("-i -- Write a Text to a made file.")
end
-- This program was created by IsaacTBest.
-- License: GNU/GPLv3 License.
-- Read GNU/GPLv3 License to know more about the laws.
local tArgs = { ... }
if #tArgs < 1 then
printUsage()
end
local sCommand = tArgs[1]
if sCommand == "-find" then
local sPath = shell.resolve( tArgs[2] )
local tFiles = fs.find( sPath )
if #tFiles > 0 then
for n,sFile in ipairs( tFiles ) do
if fs.exists( sFile ) then
print("File Exists!");
else
term.setTextColor(colors.red)
printError( "File does not exist!" )
end
end
else
printUsage()
end
end
if sCommand == "-o" then
local sPath = shell.resolve( tArgs[2] )
local tFiles = fs.find( sPath )
if #tFiles > 0 then
for n,sFile in ipairs( tFiles ) do
if fs.exists( sFile ) then
local file = fs.open( sFile,"r" )
print("Title of file: "..sFile)
print("Content:")
print(file.readAll( sFile ))
file.close()
else
term.setTextColor(colors.red)
print( "File does not exist!" )
end
end
end
end
if sCommand == "-i" then
local sPath = shell.resolve( tArgs[2] )
local tFiles = fs.find( sPath )
local tLines = shell.resolve ( tArgs[3] )
if #tFiles > 0 then
for n,sFile in ipairs( tFiles ) do
writeLines(sFile, tLines)
end
end
end
local function readLines(sPath)
local fHandle = fs.open(sPath, 'r')
if fHandle then
local tLines = {}
for sLine in fHandle.readLine do
tLines[#tLines+1] = sLine
end
fHandle.close()
return tLines
end
end
local function writeLines(sPath, tLines)
local fHandle = fs.open(sPath, 'w')
if fHandle then
fHandle.writeLine(table.concat(tLines, '\n'))
fHandle.close()
end
end
help = {}
help[1] = "yo yo yo"
help[2] = "everybody"
writeLines("newFile", help)
yo yo yo
everybody