os - os Operation#
Adapted Air780E
Note
This page document is automatically generated by this file. If there is any error, please submit issue or help modify pr, thank you!
Tip
This library has its own demo,click this link to view demo examples of OS
Example
-- os The module is a lua native module. This document is intended to facilitate the exposition of common problems in actual use.
-- Please refer to the native documentation https://wiki.luatos.org/_static/lua53doc/manual.html#6.9
os.remove(path)#
Remove File
Parameters
Incoming Value Type |
Explanation |
---|---|
string |
Full path of the file to be removed |
Return Value
return value type |
explanation |
---|---|
bool |
Returns true for success, otherwise nil |
string |
Return reason string on failure |
Examples
-- Delete a file in the root directory
os.remove("/1.txt")
-- Note that the files during line brushing are usually in the/luadb directory, and the files in this directory are read-only.
-- That is, it cannot be executed. os.remove("/luadb/xxx.bin")
os.rename(old_path, new_path)#
File Rename
Parameters
Incoming Value Type |
Explanation |
---|---|
string |
Full path of source file |
string |
target file full path |
Return Value
return value type |
explanation |
---|---|
bool |
Returns true for success, otherwise nil |
string |
Return reason string on failure |
Examples
-- Note that only files under the same file system can be renamed
-- For example:
os.rename("/1.txt", "/2.txt")
-- different file system, or the source file system is read-only,
--os.rename("/luadb/1.txt", "/luadb/2.txt")
--os.rename("/luadb/1.txt", "/2.txt")
os.clock()#
Returns an approximation of the CPU time in seconds used by the program
Parameters
Incoming Value Type |
Explanation |
---|---|
return |
Timestamp |
Return Value
None
Examples
-- Not recommend the use of this API
-- To get a timestamp, use os.time()
-- To obtain the system runtime, use mcu.ticks()
os.date(fmt, time)#
Date Function
Parameters
Incoming Value Type |
Explanation |
---|---|
string |
A formatted string, which can be nil |
table |
date-time table |
Return Value
return value type |
explanation |
---|---|
table/string |
Depending on the fmt, the return value is different |
Examples
-- A few points worth noting:
-- 1. If UTC time is required, the first character of fmt is written"!"
-- 2. fmt The formatting of follows the C function strftime, which can be consulted. https://developer.aliyun.com/article/320480
-- Get local time string
log.info("Local time string", os.date())
-- Get UTC time string
log.info("UTC Time String", os.date("!%c"))
-- Format local time string
log.info("Local time string", os.date("%Y-%m-%d %H:%M:%S"))
-- Formatting a UTC Time String
log.info("UTC Time String", os.date("!%Y-%m-%d %H:%M:%S"))
-- Format Time String
log.info("Custom time string", os.date("!%Y-%m-%d %H:%M:%S", os.time({year=2000, mon=1, day=1, hour=0, min=0, sec=0})))
-- Gets the local time of table
log.info("Local time string", json.encode(os.date("*t")))
-- Gets the UTC time table
log.info("UTC Time String", json.encode(os.date("!*t")))
os.time(mytime)#
timestamp function
Parameters
Incoming Value Type |
Explanation |
---|---|
table |
date-time table |
return |
Timestamp |
Return Value
None
Examples
-- Note that this function returns a UTC timestamp
-- timestamp, but the accuracy under lua can only reach seconds
log.info("UTC Timestamp", os.time())
log.info("Custom Timestamp", os.time({year=2000, mon=1, day=1, hour=0, min=0, sec=0}))
os.difftime(timeA, timeB)#
time difference
Parameters
Incoming Value Type |
Explanation |
---|---|
int |
Time A, numeric type |
int |
Time B, numeric type |
Return Value
return value type |
explanation |
---|---|
int |
time difference |
Examples
None