PyFatFS

PyFilesystem2 implementation of PyFAT.

class pyfatfs.PyFatFS.PyFatBytesIOFS(*args: Any, **kwargs: Any)

Bases: PyFatFS

Provide PyFatFS functionality for BytesIO or IOBase streams.

PyFilesystem2 FAT constructor, initializes self.fs with BytesIO.

Parameters:
  • fpBytesIO / IOBase: Open file, either in-memory or already open handle.

  • encodingstr: Valid Python standard encoding.

  • offsetint: Offset from file start to filesystem start in bytes.

  • preserve_casebool: By default 8DOT3 filenames do not support casing. If preserve_case is set to True, it will create an LFN entry if the casing does not conform to 8DOT3.

  • utcbool: Store timestamps in UTC rather than the local time. This applies to dentry creation, modification and last access time.

  • lazy_loadbool: Load directory entries on-demand instead of parsing the entire directory listing on mount.

class pyfatfs.PyFatFS.PyFatFS(*args: Any, **kwargs: Any)

Bases: FS

PyFilesystem2 extension.

PyFilesystem2 FAT constructor, initializes self.fs.

Parameters:
  • filenamestr: Name of file/device to open as FAT partition.

  • encodingstr: Valid Python standard encoding.

  • offsetint: Offset from file start to filesystem start in bytes.

  • preserve_casebool: By default 8DOT3 filenames do not support casing. If preserve_case is set to True, it will create an LFN entry if the casing does not conform to 8DOT3.

  • read_onlybool: If set to true, the filesystem is mounted in read-only mode, not allowing any modifications.

  • utcbool: Store timestamps in UTC rather than the local time. This applies to dentry creation, modification and last access time.

  • lazy_loadbool: Load directory entries on-demand instead of parsing the entire directory listing on mount.

close()

Clean up open handles.

create(path: str, wipe: bool = False) bool

Create a new file.

Parameters:
  • path – Path of new file on filesystem

  • wipe – Overwrite existing file contents

exists(path: str)

Verify if given path exists on filesystem.

Parameters:

path – Path to file or directory on filesystem

Returns:

Boolean value indicating entries existence

getinfo(path: str, namespaces=None)

Generate PyFilesystem2’s Info struct.

Parameters:
  • path – Path to file or directory on filesystem

  • namespaces – Info namespaces to query, NotImplemented

Returns:

Info

getmeta(namespace='standard')

Get generic filesystem metadata.

Parameters:

namespace – Namespace to query, only standard supported

Returns:

dict with file system meta data

getsize(path: str)

Get size of file in bytes.

Parameters:

path – Path to file or directory on filesystem

Returns:

Size in bytes as int

gettype(path: str)

Get type of file as ResourceType.

Parameters:

path – Path to file or directory on filesystem

Returns:

ResourceType.directory or ResourceType.file

listdir(path: str)

List contents of given directory entry.

Parameters:

path – Path to directory on filesystem

makedir(path: str, permissions: fs.permissions.Permissions = None, recreate: bool = False)

Create directory on filesystem.

Parameters:
  • path – Path of new directory on filesystem

  • permissions – Currently not implemented

  • recreate – Ignore if directory already exists

openbin(path: str, mode: str = 'r', buffering: int = -1, **options)

Open file from filesystem.

Parameters:
  • path – Path to file on filesystem

  • mode – Mode to open file in

  • buffering – TBD

Returns:

BinaryIO stream

opendir(path: str, factory=None) fs.subfs.SubFS

Get a filesystem object for a sub-directory.

Parameters:

path – str: Path to a directory on the filesystem.

remove(path: str)

Remove a file from the filesystem.

Parameters:

pathstr: Path of file to remove

removedir(path: str)

Remove empty directories from the filesystem.

Parameters:

pathstr: Directory to remove

removetree(dir_path: str)

Recursively remove the contents of a directory.

Parameters:

dir_pathstr: Path to a directory on the filesystem.

setinfo(path: str, info)

Set file meta information such as timestamps.