Library for the Minecraft mod ComputerCraft/CC: Tweaked for better interaction with files
FileUtils can be installed using the ComputerCraft Package Tool by using the following commands:
Install CCPT, only run if you havn't installed it yet:
pastebin run syAUmLaF
Install the library:
ccpt install fileutils
The library will now be stored in "/lib/fileutils".
The function file_exists([filepath]) returns true if the file exists or false if it doesn't.
Example:
Content of "test":
hi, how are you?
The function storeFile([filepath],[content]) stores [content], given as a string, in a file specified by the given [filepath]. This will overwrite the file if it already exists!
Example:
Example code and output:
Content of "test":
hi, how are you?
The function readFile([filepath],[createnew]) reads a file specified by the given [filepath]. If [createnew] is nil and the file doesn't exist, false is returned. If [createnew] is some string and the file doesn't exist, a new file with the content [createnew] is created and [createnew] is returned. This is useful if you don't know wether the file was already created, and if not some basic file structure should be built.
Examples:
1) Content of "test":
hi, how are you?
Example code and output:
2) "test" does not exist.
Example code and output:
3) "test" does not exist.
Example code and output:
Content of "test":
:)
The function storeData([filepath],[content]) stores [content], given as a table, in a file specified by the given [filepath]. This will overwrite the file if it already exists!
Example:
Example code and output:
Content of "test":
{ greeting = "'ello",}
The function readFile([filepath],[createnew]) reads a file specified by the given [filepath] as a table. If [createnew] is false and the file doesn't exist, false is returned. If [createnew] is true and the file doesn't exist, a new file with the content "{}" is created and an empty table is returned.
Examples:
1) Content of "test":
{ greeting = "'ello",}
Example code and output:
2) "test" does not exist.
Example code and output:
3) "test" does not exist.
Example code and output:
Content of "test":
{}
Nothing here yet, we are still on 1.0 :)
First of all, thanks for reading! This library is not the biggest library ever, but it turned out to be really useful for one of my projects, and maybe it is for yours too :)
If you find bugs, please create an issue so I can fix them.
I'm still very new to Github, so feel free to point out things I could do better. Also, english is not my first language, so if you find any spelling/language-related mistakes, please do also create an issue.
Have a nice day,
PentagonLP