Skip to Content
Lua Quick Start Guide
book

Lua Quick Start Guide

by Gabor Szauer
July 2018
Beginner
202 pages
5h 42m
English
Packt Publishing
Content preview from Lua Quick Start Guide

Working with files

Lua can create, rename, and delete files. We've already seen how to create files in the File IO section of this chapter. You can use io.open to create a new file:

local file = io.open("new_file.txt", "a")file:close()

Files can be renamed with the os.rename function. This function takes two arguments: the path to the file to be renamed and the path to the final, renamed version of the file. The code here renames the file created in the last sample:

os.rename("new_file.txt", "renamed_file.txt")

Files can be deleted with the os.remove function. This function takes the path of a file to delete. To remove the previously renamed file, you would have to use the following code:

os.remove("renamed_file.txt")

Lua can not natively ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Beginning Lua Programming

Beginning Lua Programming

Kurt Jung, Aaron Brown
Vim Masterclass

Vim Masterclass

Jason Cannon

Publisher Resources

ISBN: 9781789343229Supplemental Content