I am trying to make a file open and write using a path variable in a string.
so, I have
filename = nil
write"filename: "
input = read()
filename = input
h = fs.open("Mydir/filename")
filename being the variable, i have been at this for 3 hours now, and cannot figure it out.
Any help would be appreciated
Thanks,
Andrew
6 replies to this topic
#1
Posted 04 October 2012 - 12:42 PM
#2
Posted 04 October 2012 - 01:08 PM
One way is to simply concatenate the strings:
local path = "/whatever/your/path/is/" local filename = "myfile.txt" file = fs.open(path .. filename, mode) -- where mode is "r", "w" etc.
#4
Posted 04 October 2012 - 01:40 PM
Well to shorten up all of your extra variables, you could simply do
write"Filename: "
filename = read()
h = fs.open("Mydir/"..filename) -- dont have quotes around your variable
#5
Posted 25 October 2012 - 11:29 PM
jag_e_nummer_ett, on 04 October 2012 - 01:40 PM, said:
Well to shorten up all of your extra variables, you could simply do
write"Filename: "
filename = read()
h = fs.open("Mydir/"..filename) -- dont have quotes around your variable#6
Posted 25 October 2012 - 11:35 PM
Hithere__, on 25 October 2012 - 11:29 PM, said:
fs.open(path, mode)Wiki: http://computercraft.info/wiki/index.php?title=Fs.open
#7
Posted 25 October 2012 - 11:44 PM
write"Filename: "
filename = read()
h = fs.open("Mydir/"..filename, "w")
h.write("rofl")
h.close()
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











