Jump to content




Make a new folder with file in it?



7 replies to this topic

#1 ComputerCraftFan11

  • Members
  • 771 posts
  • LocationHawaii

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)?

#2 Liraal

  • New Members
  • 477 posts
  • LocationPoland

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")

#3 ComputerCraftFan11

  • Members
  • 771 posts
  • LocationHawaii

Posted 16 March 2012 - 08:49 PM

View PostLiraal, on 16 March 2012 - 08:48 PM, said:

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?

#4 ComputerCraftFan11

  • Members
  • 771 posts
  • LocationHawaii

Posted 16 March 2012 - 08:56 PM

View PostLiraal, on 16 March 2012 - 08:48 PM, said:

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

?

#5 Luanub

    Lua Nub

  • Members
  • 1,135 posts
  • LocationPortland OR

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")


#6 ComputerCraftFan11

  • Members
  • 771 posts
  • LocationHawaii

Posted 16 March 2012 - 09:06 PM

View Postluanub, on 16 March 2012 - 08:57 PM, said:

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()


#7 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 16 March 2012 - 10:44 PM

I think it's easier just to copy the file: fs.copy("path/filename", "path/newFilename")

#8 ComputerCraftFan11

  • Members
  • 771 posts
  • LocationHawaii

Posted 17 March 2012 - 03:58 AM

View PostMysticT, on 16 March 2012 - 10:44 PM, said:

I think it's easier just to copy the file: fs.copy("path/filename", "path/newFilename")

Oh...
lol





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users