134 posts
Location
Salt Lake, UT
Posted 10 June 2012 - 12:17 AM
When using the fs (API) do you need to create a directory?
1604 posts
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>").
134 posts
Location
Salt Lake, UT
Posted 10 June 2012 - 01:46 AM
k so… If i were to use fs.open() do i need to create a directory first?
1604 posts
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.
134 posts
Location
Salt Lake, UT
Posted 10 June 2012 - 06:09 AM
Thank you