Posted 09 August 2013 - 08:20 AM
Hello! I have written an api that I thought was pretty useful. It makes it easier to handle the content of a file.
Available functions for file manipulation:
Functions for file mounting:
Example of file mounting:
Download:
pastebin get g2Pn7ptb fList
Have fun! B)/>
Available functions for file manipulation:
Spoiler
fList.exist( string path ) --Returns true if path exists
fList.fPath( string path, string rValue ) --Returns either name or path of file. Example: fList.fPath("Example/Test.txt", "name" or "path") > "Test.txt" or "Example/"
fList.fTable( string path ) --Returns a table containing each line of the file in the path argument
fList.fLine( string path, number line ) --Returns the line of the file in the path argument
fList.fText( string path ) --Returns a string with all the text containing the file in the path argument
fList.fWrite( string path, string str ) --Writes the string into the file in the path argument
fList.fAppend( string path, string str ) --Appends the string into the file in the path argument
fList.fTop( string path, string str ) --Writes the string at the top of the file in the path argument
fList.fWriteTable( string path, table _table ) --Writes the content of the table into the file in the path argument
fList.fAppendTable( string path, table _table ) --Appends the content of the table into the file in the path argument
fList.fTopTable( string path, table _table ) --Writes the content of the table into the top of the file in the path argument
fList.fReplaceLine( string path, number line, string str ) --Replaces the selected line of the file in the path argument to the string argument
Functions for file mounting:
Spoiler
fList.mount.file( string path ) --Mounts the file in the path argument to the table: files
fList.mount.virtual( string name, string path, string text ) --Mounts a virtual file to the table: files
fList.mount.remove( string file or number file ) --Removes the mounted file by either enter the name of the file or the array position of the file
fList.mount.replaceLine( string file or number file, number line, string str ) --Replaces the selected line, of the mounted file, to the string argument
fList.mount.create( string file or number file ) --Writes the mounted file to the library
fList.files --Table with the mounted files. Example: fList.files[1].name > "Example.txt"
Example of file mounting:
Spoiler
fList.mount.file( "Path/Example.txt" ) --This will create a table, with the data of the selected file, within the files table like the example bellow
fList.files = {
[ #files+1 ] = {
type = "real",
name = "Example.txt",
path = "Path/",
text = --[[ <content of file> ]],
lines = --[[ <a table with all separate lines of the file> ]],
charAmount = --[[ <the amount of characters in the file> ]],
lineAmount = --[[ <the amount of lines in the file> ]]
}
}
fList.mount.virtual( "Example2.txt", "Path/", "Hello World!\nThis is an example text!" ) --This will create a table, with the data of the virtual file, within the files table like the example bellow
fList.files = {
[ #files+1 ] = {
type = "virtual",
name = "Example2.txt",
path = "Path/",
text = "Hello World!\nThis is an example text!",
lines = { [1] = "Hello World!", [2] = "This is an example text!" },
charAmount = 37,
lineAmount = 2
}
}
Download:
pastebin get g2Pn7ptb fList
Have fun! B)/>
Edited on 16 November 2013 - 06:31 AM