FileTreeEntry

class mobase.FileTreeEntry

Bases: object

Represent an entry in a file tree, either a file or a directory. This class inherited by IFileTree so that operations on entry are the same for a file or a directory.

This class provides convenience methods to query information on the file, like its name or the its last modification time. It also provides a convenience astree() method that can be used to retrieve the tree corresponding to its entry in case the entry represent a directory.

Attributes Summary

DIRECTORY

FILE

FILE_OR_DIRECTORY

Methods Summary

detach()

Detach this entry from its parent tree.

fileType()

rtype:

FileTypes

hasSuffix(**kwds)

Helper for @overload to raise when called.

isDir()

rtype:

bool

isFile()

rtype:

bool

moveTo(tree)

Move this entry to the given tree.

name()

rtype:

str

parent()

rtype:

Optional[IFileTree]

path([sep])

Retrieve the path from this entry up to the root of the tree.

pathFrom(tree[, sep])

Retrieve the path from the given tree to this entry.

suffix()

Retrieve the "last" extension of this entry.

Attributes Documentation

DIRECTORY: FileTypes = Ellipsis
FILE: FileTypes = Ellipsis
FILE_OR_DIRECTORY: FileTypes = Ellipsis

Methods Documentation

detach()

Detach this entry from its parent tree.

Return type:

bool

Returns:

True if the entry was removed correctly, False otherwise.

fileType()
Return type:

FileTypes

Returns:

The filetype of this entry.

hasSuffix(**kwds)

Helper for @overload to raise when called.

isDir()
Return type:

bool

Returns:

True if this entry is a directory, False otherwise.

isFile()
Return type:

bool

Returns:

True if this entry is a file, False otherwise.

moveTo(tree)

Move this entry to the given tree.

Return type:

bool

Parameters:

tree – The tree to move this entry to.

Returns:

True if the entry was moved correctly, False otherwise.

name()
Return type:

str

Returns:

The name of this entry.

parent()
Return type:

Optional[IFileTree]

Returns:

The parent tree containing this entry, or a None if this entry is the root

or the parent tree is unreachable.

path(sep='\\\\')

Retrieve the path from this entry up to the root of the tree.

This method propagate up the tree so is not constant complexity as the full path is never stored.

Return type:

str

Parameters:

sep – The type of separator to use to create the path.

Returns:

The path from this entry to the root, including the name of this entry.

pathFrom(tree, sep='\\\\')

Retrieve the path from the given tree to this entry.

Return type:

str

Parameters:
  • tree – The tree to reach, must be a parent of this entry.

  • sep – The type of separator to use to create the path.

Returns:

The path from the given tree to this entry, including the name of this entry, or

an empty string if the given tree is not a parent of this entry.

suffix()

Retrieve the “last” extension of this entry.

The “last” extension is everything after the last dot in the file name.

Return type:

str

Returns:

The last extension of this entry, or an empty string if the file has no extension

or is directory.