I am trying to make a program that will write data to a file for another program to be able to read the data from it. The problem is that I can't figure out a way to do this when the file i am reading and writing from is in another directory than both of my programs. I know there are other ways of doing this, but I just thought that it would be useful to know how to do it. Anyone that can help me?
Asked
Active
Viewed 1,930 times
1
-
3`..` in the filename usually means the parent directory. You could use this fact. – The Paramagnetic Croissant Nov 08 '14 at 12:22
-
Thanks! Works great! Although what if i had a file two or more directories up? – lillendogge Nov 08 '14 at 12:43
-
`../../foo.txt`... have you never *ever* written a single relative file path during your entire life? – The Paramagnetic Croissant Nov 08 '14 at 12:47
1 Answers
3
You can use the full path, e.g
local f1 = io.open('D:/test/b.txt') -- Windows
local f2 = io.open('/test/b.txt') -- Unix
or use relative path, e.g
local f = io.open('../../test/b.txt')
In this example, the file is in the test
directory of the parent directory (..
) of parent directory.

Yu Hao
- 119,891
- 44
- 235
- 294