http://powdertoy.co.uk/Wiki/api.php?action=feedcontributions&user=LittleProgramming&feedformat=atomThe Powder Toy - User contributions [en]2024-03-28T16:07:42ZUser contributionsMediaWiki 1.30.0http://powdertoy.co.uk/Wiki/index.php?title=Lua_API:File_System&diff=7996Lua API:File System2021-02-24T05:43:41Z<p>LittleProgramming: </p>
<hr />
<div>The File System API contains functions for creating, deleting, modifying and enumerating files and folders.<br />
<br />
== Methods ==<br />
<br />
=== fileSystem.list === <br />
table fs.list(string folder)<br />
Returns a table containing a list of files and folders in "folder"<br />
<br />
=== fileSystem.exists ===<br />
boolean fs.exists(string path)<br />
Returns a boolean indicating whether "path" exists as either a file or folder <br />
<br />
=== fileSystem.isFile ===<br />
boolean fs.isFile(string path)<br />
Returns a boolean indicating whether "path" exists as a file (i.e not a folder)<br />
<br />
=== fileSystem.isDirectory ===<br />
boolean fs.isDirectory(string path)<br />
Returns a boolean indicating whether "path" exists as a folder (i.e not a file)<br />
<br />
=== fileSystem.makeDirectory ===<br />
boolean fs.makeDirectory(string path)<br />
Creates the folder "path", this function is not recursive and won't create parent directories (makeDirectory("parent/child") will fail if "parent" does not exist). This function returns true on success and false on failure. <br />
<br />
=== fileSystem.removeDirectory ===<br />
boolean fs.removeDirectory(string path)<br />
Removes the empty folder specified by "path". This function returns true on success and false on failure. <br />
<br />
=== fileSystem.removeFile ===<br />
boolean fs.removeFile(string path)<br />
Removes the file "path". This function returns true on success and false on failure. <br />
<br />
=== fileSystem.move ===<br />
boolean fs.move(string path, string newPath)<br />
Moves the file or folder specified by "path" to "newPath". This function returns true on success and false on failure. <br />
<br />
=== fileSystem.copy ===<br />
boolean fs.copy(string path, string newPath)<br />
Copies the file "path" to "newPath". This function returns true on success and false on failure.<br />
<br />
== Interacting with the disk ==<br />
===Setting things up===<br />
To do a write or read from the disk, we must open an IO port.<br />
(x)=io.open((path),"(W for write, R for read)")<br />
===Writing/creating files===<br />
After you have inputted the setup code, you do not have to input a directory.<br />
(x):write((insert data here))<br />
===Reading===<br />
If you choose to read instead, you must put in the following code:<br />
(y) = (x):read((insert char numbers here, leave blank for full file))<br />
Alternatively, you can put the (x):read inside of an argument for data.<br />
===Closing it up===<br />
While I am not sure what this code does or if it's even required, at the end of each operation in the scripts I was studying, there was the following code before the lua end.<br />
(x):close()<br />
[[Category:Lua]]</div>LittleProgramminghttp://powdertoy.co.uk/Wiki/index.php?title=Lua_API:File_System&diff=7995Lua API:File System2021-02-24T05:41:49Z<p>LittleProgramming: About time this page was updated. I've been trying for 3 hours to get reading/writing files to work.</p>
<hr />
<div>The File System API contains functions for creating, deleting, modifying and enumerating files and folders.<br />
<br />
== Methods ==<br />
<br />
=== fileSystem.list === <br />
table fs.list(string folder)<br />
Returns a table containing a list of files and folders in "folder"<br />
<br />
=== fileSystem.exists ===<br />
boolean fs.exists(string path)<br />
Returns a boolean indicating whether "path" exists as either a file or folder <br />
<br />
=== fileSystem.isFile ===<br />
boolean fs.isFile(string path)<br />
Returns a boolean indicating whether "path" exists as a file (i.e not a folder)<br />
<br />
=== fileSystem.isDirectory ===<br />
boolean fs.isDirectory(string path)<br />
Returns a boolean indicating whether "path" exists as a folder (i.e not a file)<br />
<br />
=== fileSystem.makeDirectory ===<br />
boolean fs.makeDirectory(string path)<br />
Creates the folder "path", this function is not recursive and won't create parent directories (makeDirectory("parent/child") will fail if "parent" does not exist). This function returns true on success and false on failure. <br />
<br />
=== fileSystem.removeDirectory ===<br />
boolean fs.removeDirectory(string path)<br />
Removes the empty folder specified by "path". This function returns true on success and false on failure. <br />
<br />
=== fileSystem.removeFile ===<br />
boolean fs.removeFile(string path)<br />
Removes the file "path". This function returns true on success and false on failure. <br />
<br />
=== fileSystem.move ===<br />
boolean fs.move(string path, string newPath)<br />
Moves the file or folder specified by "path" to "newPath". This function returns true on success and false on failure. <br />
<br />
=== fileSystem.copy ===<br />
boolean fs.copy(string path, string newPath)<br />
Copies the file "path" to "newPath". This function returns true on success and false on failure.<br />
<br />
== Interacting with the disk ==<br />
===Setting things up===<br />
To do a write or read from the disk, we must open an IO port.<br />
(x)=io.open((path),"(W for write, R for read)")<br />
===Writing/creating files===<br />
After you have inputted the setup code, you do not have to input a directory.<br />
(x):write((insert data here))<br />
===Reading===<br />
If you choose to read instead, you must put in the following code:<br />
(y) = (x):read((insert char numbers here, leave blank for full file))<br />
===Closing it up===<br />
While I am not sure what this code does or if it's even required, at the end of each operation in the scripts I was studying, there was the following code before the lua end.<br />
(x):close()<br />
[[Category:Lua]]</div>LittleProgramming