This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
ComputerCraftFan11's profile picture

Make a new folder with file in it?

Started by ComputerCraftFan11, 16 March 2012 - 07:37 PM
ComputerCraftFan11 #1
Posted 16 March 2012 - 08:37 PM
How can I make a program create a directory called "websites" and make a file in it with the code:
Test = "Hello"
Print(Test)?
Liraal #2
Posted 16 March 2012 - 08:48 PM
mkdir websites or in lua fs.makeDir("websites")
accessing it
/websites/filename or in lua fs.open("websites/filename")
ComputerCraftFan11 #3
Posted 16 March 2012 - 08:49 PM
mkdir websites or in lua fs.makeDir("websites")
accessing it
/websites/filename or in lua fs.open("websites/filename")

How can I print text into it? Like writing print("hello") in it?
ComputerCraftFan11 #4
Posted 16 March 2012 - 08:56 PM
mkdir websites or in lua fs.makeDir("websites")
accessing it
/websites/filename or in lua fs.open("websites/filename")

Can I do

File = fs.open("websites/filenname")

File:write("print("test")")

File:close

?
Luanub #5
Posted 16 March 2012 - 08:57 PM
Should be something like


fs.open("filename", "w")
io.write("hello")

or


io.open("filename", "w+")
io.write("hello")
ComputerCraftFan11 #6
Posted 16 March 2012 - 09:06 PM
Should be something like


fs.open("filename", "w")
io.write("hello")

or


io.open("filename", "w+")
io.write("hello")

How do i make it print hello when i run it?

Because I actually wanna make a file with THIS code in it:

local homepage = "home";
local website = "www.newsite.com";
local nw = "";
local idd = os.computerID()
local port1 = idd * 32
local port2 = 0
local port3 = port2 / 32
local line1 = "This website is currently down or has not been edited. If you are the owner of this website please check your webservers or contact your webserver manager for further assistance."
local line2 = ""
local line3 = ""
local line4 = ""
local line5 = ""
rednet.open("right")
rednet.open("left")
rednet.open("front")
rednet.open("back")
local function cPrint(text)
local x,y = term.getSize()
local x2,y2 = term.getCursorPos()
term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
print(text)
end
function home()
print("Welcome to RedNet explorer! This requires you to have a wireless modem on the right side of your computer. This is the default homepage. A homepage option might be added in 1.2")
print("Host a website at:		 ")
print("www.newsite.com!		   ")
print("   -ComputerCraftFan11	 ")
end
function newsite()
cPrint("Rednet Site Manager")
print("")
print("Welcome to the rednet site manager!")
print("To make a new website, enter a domain name (.com will NOT be added for you.):")
end
function newsite2()
cPrint("Rednet Site Manager")
print("")
print("People can connect to this site by going to www." ..nw.. "")
print("You can edit this site by going to www." ..nw.. "/editor/" ..idd)
id, message  = rednet.receive()
if message == "www." ..nw.. "" then -- If someone tries to connect, it will send back the website
  sleep(1)
  rednet.send(id, line1)
  rednet.send(id, line2)
  rednet.send(id, line3)
  rednet.send(id, line4)
  rednet.send(id, line5)
elseif message == "www." ..nw.. "/editor/" ..idd then -- If someone tries to connect, it will send back the website
  sleep(1)
  rednet.send(id, "epanst")
else
  line1 = message
  id, message = rednet.receive()
  line2 = message
  id, message = rednet.receive()
  line3 = message
  id, message = rednet.receive()
  line4 = message
  id, message = rednet.receive()
  line5 = message
end
drawScreen()
end
function drawScreen()
term.clear()
term.setCursorPos(1,1)
cPrint("Rednet Explorer 1.2")

cPrint("rdnt://"..website)
print("")

if website == "www.newsite.com" then
  newsite()
elseif website == "www.newsite.com/nsite/index.php?/" then
  newsite2()
else
  write("Port:")
  port = read()
  port2 = port
  port3 = port2 / 32
end


print("")

if website == "www.newsite.com" then
  write("www.")
  nw = read()
  newsite = nw
  website = "www.newsite.com/nsite/index.php?/"
  drawScreen()
end
end
drawScreen()
MysticT #7
Posted 16 March 2012 - 10:44 PM
I think it's easier just to copy the file: fs.copy("path/filename", "path/newFilename")
ComputerCraftFan11 #8
Posted 17 March 2012 - 03:58 AM
I think it's easier just to copy the file: fs.copy("path/filename", "path/newFilename")

Oh…
lol