fs.delete

From ComputerCraft
Jump to: navigation, search

fs.delete
Function
Syntax
fs.delete()
Returns nil
API fs
Source CC:Tweaked (source)

Deletes the file or directory at the path path. If path is a directory, it will delete the directory as well as all the files inside.

Warning Warning: This function is irreversible! Make sure you enter the arguments carefully so that you do not delete anything important.
ExampleExampleDelete a file
Creates and deletes the file foo.lua, checking if it exists after each.
Code
print("Making foo.lua")
local f = fs.open("foo.lua", "w")
f.close()
print("Foo exists:", fs.exists("foo.lua"))
print("Deleting foo.lua")
fs.delete("foo.lua")
print("Foo exists:", fs.exists("foo.lua"))
Output
Making foo
Foo exists: true
Deleting foo
Foo exists: false
ExampleExampleDelete a directory
Creates and deletes the directory foo, checking if it exists after each.
Code
print("Making foo")
fs.makeDir("foo")
print("Foo exists:", fs.exists("foo"))
print("Deleting foo")
fs.delete("foo")
print("Foo exists:", fs.exists("foo"))
Output
Making foo
Foo exists: true
Deleting foo
Foo exists: false