fluentfs.filelike.file.File

class fluentfs.filelike.file.File(path: str, expand_user: bool = True, expand_vars: bool = True)

Bases: FileLike

__init__(path: str, expand_user: bool = True, expand_vars: bool = True) None

Methods

__init__(path[, expand_user, expand_vars])

t([encoding, raise_on_decode_error])

Get a TextFile object for this file.

text_file([encoding, raise_on_decode_error])

Get a TextFile object for this file.

Attributes

access_time

The last access time of this file.

atime

The last access time of this file.

byte_count

The number of bytes of this file.

bytes

The content of the file.

dir

The directory containing this file.

ext

The extension of this file.

extension

The extension of this file.

mod_time

The last modification time of this file.

mtime

The last modification time of this file.

name

path

The maximally expanded path of the file-like object.

relative_path

relpath

size

The size of this file.

property access_time: datetime

The last access time of this file.

Returns:

A datetime object representing the last access time.

property atime: datetime

The last access time of this file.

Returns:

A datetime object representing the last access time.

property byte_count: int

The number of bytes of this file.

This is similar to wc -c $FILENAME.

Returns:

The number of bytes.

property bytes: bytes

The content of the file.

Returns:

The content bytes.

property dir: Dir

The directory containing this file.

Returns:

A Dir object representing the directory.

property ext: str

The extension of this file.

Returns:

The extension. If the file has no extension, an empty string will be returned. Otherwise, the extension without the preceding dot will be returned (e.g. “txt”, not “.txt”).

property extension: str

The extension of this file.

Returns:

The extension. If the file has no extension, an empty string will be returned. Otherwise, the extension without the preceding dot will be returned (e.g. “txt”, not “.txt”).

property mod_time: datetime

The last modification time of this file.

Returns:

A datetime object representing the last modification time.

property mtime: datetime

The last modification time of this file.

Returns:

A datetime object representing the last modification time.

property path: str

The maximally expanded path of the file-like object.

property size: FileSize

The size of this file.

Returns:

A FileSize object representing the size of this file (in bytes).

t(encoding: str = 'utf-8', raise_on_decode_error: bool = True) TextFile

Get a TextFile object for this file.

Note that you are responsible to ensure that the underlying file is a valid text file (since this is very expensive to ensure automatically). This function will always succeed, even if the underlying file is not a valid text file. However, when calling paths on the resulting TextFile object, errors will occur.

Parameters:

encoding – The encoding to use.

Returns:

The obtained TextFile object.

text_file(encoding: str = 'utf-8', raise_on_decode_error: bool = True) TextFile

Get a TextFile object for this file.

Note that you are responsible to ensure that the underlying file is a valid text file (since this is very expensive to ensure automatically). This function will always succeed, even if the underlying file is not a valid text file. However, when calling paths on the resulting TextFile object, errors will occur.

Parameters:

encoding – The encoding to use.

Returns:

The obtained TextFile object.