项目作者: PentagonLP

项目描述 :
Library for ComputerCraft/CC: Tweaked to interact with files
高级语言: Lua
项目地址: git://github.com/PentagonLP/fileutils.git
创建时间: 2021-06-02T20:32:31Z
项目社区:https://github.com/PentagonLP/fileutils

开源协议:MIT License

下载


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:

  1. pastebin run syAUmLaF

Install the library:

  1. 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”:

  1. 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”:

  1. 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”:

  1. 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”:

  1. :)

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”:

  1. { 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”:

  1. { 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”:

  1. {}

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