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

FS (API)

Started by tfoote, 09 June 2012 - 10:17 PM
tfoote #1
Posted 10 June 2012 - 12:17 AM
When using the fs (API) do you need to create a directory?
MysticT #2
Posted 10 June 2012 - 01:43 AM
I don't understand the question. Do you want to create a directory? If that's it, you have to use fs.makeDir("<directory name>").
tfoote #3
Posted 10 June 2012 - 01:46 AM
k so… If i were to use fs.open() do i need to create a directory first?
MysticT #4
Posted 10 June 2012 - 01:54 AM
Depending on the mode you want to open the file there's some requirements:
To open in read mode ("r" or "rb"), the file must exist. Using fs.open("path/to/file", "r"), will return nil (couldn't open the file) if:
- The file doesn't exist.
- The path points to a directory.
- The file is already open.
To open in write mode ("w", "a", "wb" or "ab"), the path must exist, but the file doesn't (it would overwrite it if it does). So, you can't create a file in a directory that doesn't exist, you need to create it first. Using fs.open("path/to/file", "w"), will return nil (couldn't open or create the file) if:
- The path is not valid (some directory on the path doesn't exist).
- The path points to a directory.
- The file is already open.
tfoote #5
Posted 10 June 2012 - 06:09 AM
Thank you