Difference between revisions of "Lua API:File System"

From The Powder Toy
Jump to: navigation, search
(About time this page was updated. I've been trying for 3 hours to get reading/writing files to work.)
m (Remove 98.0 note)
 
(3 intermediate revisions by 3 users not shown)
Line 18: Line 18:
 
  boolean fs.isDirectory(string path)
 
  boolean fs.isDirectory(string path)
 
Returns a boolean indicating whether "path" exists as a folder (i.e not a file)
 
Returns a boolean indicating whether "path" exists as a folder (i.e not a file)
 +
 +
=== fileSystem.isLink ===
 +
boolean fs.isLink(string path)
 +
'''This function is part of an upcoming version, and not present in 97.0'''
 +
 +
Returns a boolean indicating whether "path" is a symbolic link
  
 
=== fileSystem.makeDirectory ===
 
=== fileSystem.makeDirectory ===
Line 32: Line 38:
  
 
=== fileSystem.move ===
 
=== fileSystem.move ===
  boolean fs.move(string path, string newPath)
+
  boolean fs.move(string path, string newPath, bool replace)
Moves the file or folder specified by "path" to "newPath". This function returns true on success and false on failure.  
+
Moves the file or folder specified by "path" to "newPath". This function returns true on success and false on failure.
 +
 
 +
The "replace" parameter controls whether or not the rename should fail if "newPath" already exists. By default, replace is false.
  
 
=== fileSystem.copy ===
 
=== fileSystem.copy ===
Line 39: Line 47:
 
Copies the file "path" to "newPath". This function returns true on success and false on failure.
 
Copies the file "path" to "newPath". This function returns true on success and false on failure.
  
== Interacting with the disk ==
 
===Setting things up===
 
To do a write or read from the disk, we must open an IO port.
 
(x)=io.open((path),"(W for write, R for read)")
 
===Writing/creating files===
 
After you have inputted the setup code, you do not have to input a directory.
 
(x):write((insert data here))
 
===Reading===
 
If you choose to read instead, you must put in the following code:
 
(y) = (x):read((insert char numbers here, leave blank for full file))
 
===Closing it up===
 
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.
 
(x):close()
 
 
[[Category:Lua]]
 
[[Category:Lua]]

Latest revision as of 04:16, 30 March 2024

The File System API contains functions for creating, deleting, modifying and enumerating files and folders.

Methods

fileSystem.list

table fs.list(string folder)

Returns a table containing a list of files and folders in "folder"

fileSystem.exists

boolean fs.exists(string path)

Returns a boolean indicating whether "path" exists as either a file or folder

fileSystem.isFile

boolean fs.isFile(string path)

Returns a boolean indicating whether "path" exists as a file (i.e not a folder)

fileSystem.isDirectory

boolean fs.isDirectory(string path)

Returns a boolean indicating whether "path" exists as a folder (i.e not a file)

fileSystem.isLink

boolean fs.isLink(string path)

This function is part of an upcoming version, and not present in 97.0

Returns a boolean indicating whether "path" is a symbolic link

fileSystem.makeDirectory

boolean fs.makeDirectory(string path)

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.

fileSystem.removeDirectory

boolean fs.removeDirectory(string path)

Removes the empty folder specified by "path". This function returns true on success and false on failure.

fileSystem.removeFile

boolean fs.removeFile(string path)

Removes the file "path". This function returns true on success and false on failure.

fileSystem.move

boolean fs.move(string path, string newPath, bool replace)

Moves the file or folder specified by "path" to "newPath". This function returns true on success and false on failure.

The "replace" parameter controls whether or not the rename should fail if "newPath" already exists. By default, replace is false.

fileSystem.copy

boolean fs.copy(string path, string newPath)

Copies the file "path" to "newPath". This function returns true on success and false on failure.