-
Notifications
You must be signed in to change notification settings - Fork 0
File system
The Lua RTOS file system functions provides access to the supported file systems. Some functions, such as create a directory, are provided as an extension of the Lua os and module.
File access functions are provided through the standard Lua io module. These functions are not documented in this wiki, please refer to this link for give more information.
The functions of this module are organized in the following categories:
List partitions available on the device.
Arguments: nothing
Returns: the available partitions, partition types, names, encoded-state, start addresses and lengths in bytes.
/ > os.partitions()
TYPE:SUB ADDRESS LENGTH ENC LABEL
0x00:0x10 655360 1769472 N ota_0 < boot < running
0x00:0x11 2424832 1769472 N ota_1
0x01:0x02 36864 24576 N nvs
0x01:0x40 61440 524288 N storage
0x01:0x01 585728 4096 N phy_init
0x01:0x00 589824 8192 N otadata
/ >
Format a file system. Because all data is removed in the format process the function ask for a confirmation.
Arguments:
- file system: a string identifying the file system. Can be either spiffs or fat.
Returns: nothing or an exception.
/ > os.format("fat")
All data in fat will be deleted. Continue? [y/n]: y
Formatting...
Initializing FAT area: 4% completed
Show (but not modify) the contents of a text file to the screen.
Arguments:
- filename: file path to show. Path can be absolute or relative to current working directory.
Returns: nothing or an error.
Change the current working directory.
Arguments:
- path: directory path. Path can be absolute or relative to current working directory.
Returns: nothing.
/> os.cd("/examples")
/examples >
Show (but not modify) the contents of the system log file one screen at a time. The content is paging through text one screenful at a time.
Note: os.dmseg() is not available in file systems that use NOR flash technology for store it's data, such as SPIFFS.
Edits a file.
Arguments:
- file: file path. Can be absolute or relative to current working directory.
Returns: nothing
/> os.edit("autorun.lua")
List the path contents. Limited wildcard support.
Arguments:
- path: directory path. This argument it's optional, and if is not provided the contents of the current directory are listed. Path can be absolute or relative to current working directory.
Returns: nothing
/> os.ls("/")
d - tmp
d - www
d - conf
d - log
d - lib
f 27 test1.lua
f 956 autorun.lua
f 1871 lcd.lua
/examples/lua > os.ls("/*.lua")
f 2407 config.lua
f 1034 autorun.lua
f 2446 system.lua
f 1105 settings.lua
/examples/lua >
Directory contents is listed on the screen in columns (separated by tab):
- first column: entry type (d = directory / f = file)
- second column: entry size in bytes
- third column: entry name
Make a directory.
Arguments:
- directory path. Path can be absolute or relative to current working directory.
Returns: true if success
-- Make a new directory named test into the current working directory
os.mkdir("test")
true
Show (but not modify) the contents of a text file one screen at a time. The content is paging through text one screenful at a time.
Arguments:
- filename: file path to show. Path can be absolute or relative to current working directory.
Returns: nothing or an error.
Get the current working directory.
Arguments: nothing
Returns: the current directory
/examples > os.pwd()
/examples
Remove a file or a directory. Limited wildcard support.
Arguments:
- path: file or directory path to remove. Path can be absolute or relative to current working directory.
Returns: nothing or an error.
/examples/lua > os.remove("*.bak")
/examples/lua >
Rename a file or a directory.
Arguments:
- old path: file or directory path to rename. Path can be absolute or relative to current working directory.
- new path: file or directory new path. Path can be absolute or relative to current working directory.
Returns: nothing or an error.
Copy a file.
Arguments:
- source path: file source path
- destination path: file destination path
Returns: nothing
-- Copy autorun.lua into autorun.old
os.cp("/autorun.lua","/autorun.old")