maix::fs

maix.fs module

This is maix::fs module of MaixCDK.
All of these elements are in namespace maix::fs.

For MaixCDK developer: DO NOT edit this doc file manually, this doc is auto generated!

Module

No module

Enum

SEEK

SEEK enums

item describe
values SEEK_SET: Seek from beginning of file.
SEEK_CUR: Seek from current position.
SEEK_END: Seek from end of file.

C++ defination code:

enum SEEK
    {
        SEEK_SET = 0,  // Seek from beginning of file.
        SEEK_CUR = 1,  // Seek from current position.
        SEEK_END = 2,  // Seek from end of file.
    }

Variable

Function

isabs

Check if the path is absolute path

item description
param path: path to check
return true if path is absolute path

C++ defination code:

bool isabs(const std::string &path)

isdir

Check if the path is a directory, if not exist, throw exception

item description
param path: path to check
return true if path is a directory

C++ defination code:

bool isdir(const std::string &path)

isfile

Check if the path is a file, if not exist, throw exception

item description
param path: path to check
return true if path is a file

C++ defination code:

bool isfile(const std::string &path)

Check if the path is a link, if not exist, throw exception

item description
param path: path to check
return true if path is a link

C++ defination code:

bool islink(const std::string &path)

Create soft link

item description
param src: real file path
link: link file path
force: force link, if already have link file, will delet it first then create.

C++ defination code:

err::Err symlink(const std::string &src, const std::string &link, bool force = false)

exists

Check if the path exists

item description
param path: path to check
return true if path exists

C++ defination code:

bool exists(const std::string &path)

mkdir

Create a directory recursively

item description
param path: path to create
exist_ok: if true, also return true if directory already exists
recursive: if true, create directory recursively, otherwise, only create one directory, default is true
return err::ERR_NONE(err.Err.ERR_NONE in MaixPy) if success, other error code if failed

C++ defination code:

err::Err mkdir(const std::string &path, bool exist_ok = true, bool recursive = true)

rmdir

Remove a directory

item description
param path: path to remove
recursive: if true, remove directory recursively, otherwise, only remove empty directory, default is false
return err::ERR_NONE(err.Err.ERR_NONE in MaixPy) if success, other error code if failed

C++ defination code:

err::Err rmdir(const std::string &path, bool recursive = false)

remove

Remove a file

item description
param path: path to remove
return err::ERR_NONE(err.Err.ERR_NONE in MaixPy) if success, other error code if failed

C++ defination code:

err::Err remove(const std::string &path)

rename

Rename a file or directory

item description
param src: source path
dst: destination path, if destination dirs not exist, will auto create
return err::ERR_NONE(err.Err.ERR_NONE in MaixPy) if success, other error code if failed

C++ defination code:

err::Err rename(const std::string &src, const std::string &dst)

sync

Sync files, ensure they're wrriten to disk from RAM

C++ defination code:

void sync()

getsize

Get file size

item description
param path: path to get size
return file size if success, -err::Err code if failed

C++ defination code:

int getsize(const std::string &path)

dirname

Get directory name of path

item description
param path: path to get dirname
return dirname if success, empty string if failed

C++ defination code:

std::string dirname(const std::string &path)

basename

Get base name of path

item description
param path: path to get basename
return basename if success, empty string if failed

C++ defination code:

std::string basename(const std::string &path)

abspath

Get absolute path

item description
param path: path to get absolute path
return absolute path if success, empty string if failed

C++ defination code:

std::string abspath(const std::string &path)

getcwd

Get current working directory

item description
return current working directory absolute path

C++ defination code:

std::string getcwd()

realpath

Get realpath of path

item description
param path: path to get realpath
return realpath if success, empty string if failed

C++ defination code:

std::string realpath(const std::string &path)

splitext

Get file extension

item description
param path: path to get extension
return prefix_path and extension list if success, empty string if failed

C++ defination code:

std::vector<std::string> splitext(const std::string &path)

listdir

List files in directory

item description
param path: path to list
recursive: if true, list recursively, otherwise, only list current directory, default is false
full_path: if true, return full path, otherwise, only return basename, default is false
return files list if success, nullptr if failed, you should manually delete it in C++.

C++ defination code:

std::vector<std::string> *listdir(const std::string &path, bool recursive = false, bool full_path = false)

open

Open a file, and return a File object

item description
param path: path to open
mode: open mode, support "r", "w", "a", "r+", "w+", "a+", "rb", "wb", "ab", "rb+", "wb+", "ab+"
return File object if success(need to delete object manually in C/C++), nullptr if failed

C++ defination code:

fs::File *open(const std::string &path, const std::string &mode)

tempdir

Get temp files directory

item description
return temp files directory

C++ defination code:

std::string tempdir()

Class

File

File read write ops

C++ defination code:

class File

File

Construct File object

item description
type func
static False

C++ defination code:

File()

open

Open a file

item description
type func
param path: path to open
mode: open mode, support "r", "w", "a", "r+", "w+", "a+", "rb", "wb", "ab", "rb+", "wb+", "ab+"
return err::ERR_NONE(err.Err.ERR_NONE in MaixPy) if success, other error code if failed
static False

C++ defination code:

err::Err open(const std::string &path, const std::string &mode)

close

Close a file

item description
type func
static False

C++ defination code:

void close()

read

Read data from file

item description
type func
param buf: buffer to store data
size: buffer size(max read size)
return read size if success, -err::Err code if failed
static False

C++ defination code:

int read(void *buf, int size)

read (overload 1)

Read data from file API2

item description
type func
param size: max read size
return bytes data if success(need delete manually in C/C++), nullptr if failed
static False

C++ defination code:

std::vector<uint8_t> *read(int size)

readline

Read line from file

item description
type func
param line: buffer to store line
return read size if success, -err::Err code if failed
static False

C++ defination code:

int readline(std::string &line)

readline (overload 1)

Read line from file

item description
type func
return line if success, None(nullptr in C++) if failed. You need to delete the returned object manually in C/C++.
static False

C++ defination code:

std::string *readline()

eof

End of file or not

item description
type func
return 0 if not reach end of file, else eof.
static False

C++ defination code:

int eof()

write

Write data to file

item description
type func
param buf: buffer to write
size: buffer size
return write size if success, -err::Err code if failed
static False

C++ defination code:

int write(const void *buf, int size)

write (overload 1)

Write data to file API2

item description
type func
param buf: buffer to write
return write size if success, -err::Err code if failed
static False

C++ defination code:

int write(const std::vector<uint8_t> &buf)

seek

Seek file position

item description
type func
param offset: offset to seek
whence: @see maix.fs.SEEK
return new position if success, -err::Err code if failed
static False

C++ defination code:

int seek(int offset, int whence)

tell

Get file position

item description
type func
return file position if success, -err::Err code if failed
static False

C++ defination code:

int tell()

flush

Flush file

item description
type func
return err::ERR_NONE(err.Err.ERR_NONE in MaixPy) if success, other error code if failed
static False

C++ defination code:

err::Err flush()