maix.fs

maix.fs module

You can use maix.fs to access this module with MaixPy
This module is generated from MaixCDK

Module

No module

Enum

SEEK

item doc
brief SEEK enums
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

def isabs(path: str) -> bool
item doc
brief Check if the path is absolute path
param path: path to check
return true if path is absolute path

C++ defination code:

bool isabs(const std::string &path)

isdir

def isdir(path: str) -> bool
item doc
brief Check if the path is a directory, if not exist, throw exception
param path: path to check
return true if path is a directory

C++ defination code:

bool isdir(const std::string &path)

isfile

def isfile(path: str) -> bool
item doc
brief Check if the path is a file, if not exist, throw exception
param path: path to check
return true if path is a file

C++ defination code:

bool isfile(const std::string &path)
def islink(path: str) -> bool
item doc
brief Check if the path is a link, if not exist, throw exception
param path: path to check
return true if path is a link

C++ defination code:

bool islink(const std::string &path)
def symlink(src: str, link: str, force: bool = False) -> maix.err.Err
item doc
brief Create soft link
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

def exists(path: str) -> bool
item doc
brief Check if the path exists
param path: path to check
return true if path exists

C++ defination code:

bool exists(const std::string &path)

mkdir

def mkdir(path: str, exist_ok: bool = True, recursive: bool = True) -> maix.err.Err
item doc
brief Create a directory recursively
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

def rmdir(path: str, recursive: bool = False) -> maix.err.Err
item doc
brief Remove a directory
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

def remove(path: str) -> maix.err.Err
item doc
brief Remove a file
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

def rename(src: str, dst: str) -> maix.err.Err
item doc
brief Rename a file or directory
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

def sync() -> None
item doc
brief Sync files, ensure they're wrriten to disk from RAM

C++ defination code:

void sync()

getsize

def getsize(path: str) -> int
item doc
brief Get file size
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

def dirname(path: str) -> str
item doc
brief Get directory name of path
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

def basename(path: str) -> str
item doc
brief Get base name of path
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

def abspath(path: str) -> str
item doc
brief Get absolute path
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

def getcwd() -> str
item doc
brief Get current working directory
return current working directory absolute path

C++ defination code:

std::string getcwd()

realpath

def realpath(path: str) -> str
item doc
brief Get realpath of path
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

def splitext(path: str) -> str
item doc
brief Get file extension
param path: path to get extension
return extension if success, empty string if failed

C++ defination code:

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

listdir

def listdir(path: str, recursive: bool = False, full_path: bool = False) -> list[str]
item doc
brief List files in directory
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

def open(self, path: str, mode: str) -> maix.err.Err
item doc
brief Open a file, and return a File object
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

def tempdir() -> str
item doc
brief Get temp files directory
return temp files directory

C++ defination code:

std::string tempdir()

Class

File

item doc
brief File read write ops

C++ defination code:

class File

__init__

def __init__(self) -> None
item doc
type func
brief Construct File object
static False

C++ defination code:

File()

open

def open(self, path: str, mode: str) -> maix.err.Err
item doc
type func
brief Open a file
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

def close(self) -> None
item doc
type func
brief Close a file
static False

C++ defination code:

void close()

read

def read(self, size: int) -> list[int]
item doc
type func
brief Read data from file API2
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

def readline(self) -> str
item doc
type func
brief Read line from file
return line if success, empty string if failed. You need to delete the returned object manually in C/C++.
static False

C++ defination code:

std::string *readline()

write

def write(self, buf: list[int]) -> int
item doc
type func
brief Write data to file API2
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

def seek(self, offset: int, whence: int) -> int
item doc
type func
brief Seek file position
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

def tell(self) -> int
item doc
type func
brief Get file position
return file position if success, -err::Err code if failed
static False

C++ defination code:

int tell()

flush

def flush(self) -> maix.err.Err
item doc
type func
brief Flush file
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()