lfs.* (file system)

Type Library
Revision Release 2022.3683
Keywords lfs, LuaFileSystem, files, file system
See also LuaFileSystem Reference

Overview

LuaFileSystem provides functionality to perform various file-related tasks, including but not limited to:

To delete a directory or file, please refer to os.remove().

To rename a directory or file, please refer to os.rename().

Examples

Traverse a Directory
local lfs = require( "lfs" )

-- Get raw path to the app documents directory
local doc_path = system.pathForFile( "", system.DocumentsDirectory )

for file in lfs.dir( doc_path ) do
    -- "file" is the current file or directory name
    print( "Found file: " .. file )
end
Working With Directories
local lfs = require( "lfs" )

-- Get raw path to the app temporary directory
local temp_path = system.pathForFile( "", system.TemporaryDirectory )

-- Change current working directory
local success = lfs.chdir( temp_path )  --returns true on success
local new_folder_path

if ( success ) then
lfs.mkdir( "MyNewFolder" )
    new_folder_path = lfs.currentdir() .. "/MyNewFolder"
end