Skip to content

Library for ComputerCraft/CC: Tweaked to interact with files

License

Notifications You must be signed in to change notification settings

PentagonLP/fileutils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FileUtils

projectstage projectstage license issues
contributors activity lastcommit
size files languages

Library for the Minecraft mod ComputerCraft/CC: Tweaked for better interaction with files

How to install

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".

How to use

1. Check if file exists

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?

Example code and output:
missing image :(

2. Store some content in a file

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:
missing image :(
Content of "test":

hi, how are you?

3. Read some content from a file

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:
missing image :(
2) "test" does not exist.

Example code and output:
missing image :(
3) "test" does not exist.

Example code and output:
missing image :(
Content of "test":

:)

4. Store a table in a file

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:
missing image :(
Content of "test":

{  greeting = "'ello",}

3. Read a table from a file

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:
missing image :(
2) "test" does not exist.

Example code and output:
missing image :(
3) "test" does not exist.

Example code and output:
missing image :(
Content of "test":

{}

Changelog

Nothing here yet, we are still on 1.0 :)

Last words

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

About

Library for ComputerCraft/CC: Tweaked to interact with files

Topics

Resources

License

Stars

Watchers

Forks

Languages