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

How to get to a file up a folder?

Started by DannySMc, 20 October 2014 - 11:21 AM
DannySMc #1
Posted 20 October 2014 - 01:21 PM
So I want to make loads of programs that are put in a folder called: /programs/ but I want to be able to get the root directory again, to talk to the main program? how do I do this? as HTML uses:
../main.lua (for example)

example:


/
   - programs/
	  - test1.lua
   - games/
	  - game1.lua
	  - game2.lua
   - apis/
   - main.lua
   - startup

how do i get the test1.lua to get to the main.lua in the root?
Edited on 20 October 2014 - 11:21 AM
MKlegoman357 #2
Posted 20 October 2014 - 02:05 PM
It depends on what you want to do with the main file and if you want to do anything with the file at all. If you just want to make two running programs communicate you can use os.queueEvent() or using some other external API. Note that most of the fs API works with absolute and not relative paths. The root of the computer's HDD most of the time is just a single slash ( / ).
Bomb Bloke #3
Posted 21 October 2014 - 01:40 AM
If you specifically want to refer to a file in the parent directory of any given subdirectory relatively, use shell.resolve():

shell.resolve("../main.lua")

As MKlegoman357 says, this isn't needed if you already know where the parent directory is. In this case it sounds like you could just refer to "/main.lua" directly, as an absolute path.
Edited on 20 October 2014 - 11:41 PM