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()

returns

The filetype of this entry.

hasSuffix(**kwds)

Helper for @overload to raise when called.

isDir()

returns

True if this entry is a directory, False otherwise.

isFile()

returns

True if this entry is a file, False otherwise.

moveTo(tree)

Move this entry to the given tree.

name()

returns

The name of this entry.

parent()

returns

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

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: FileTreeEntry.FileTypes = Ellipsis
FILE: FileTreeEntry.FileTypes = Ellipsis
FILE_OR_DIRECTORY: FileTreeEntry.FileTypes = Ellipsis

Methods Documentation

detach()

Detach this entry from its parent tree.

Returns

True if the entry was removed correctly, False otherwise.

Return type

bool

fileType()
Returns

The filetype of this entry.

Return type

FileTypes

hasSuffix(**kwds)

Helper for @overload to raise when called.

isDir()
Returns

True if this entry is a directory, False otherwise.

Return type

bool

isFile()
Returns

True if this entry is a file, False otherwise.

Return type

bool

moveTo(tree)

Move this entry to the given tree.

Parameters

tree – The tree to move this entry to.

Returns

True if the entry was moved correctly, False otherwise.

Return type

bool

name()
Returns

The name of this entry.

Return type

str

parent()
Returns

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

or the parent tree is unreachable.

Return type

Optional[IFileTree]

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.

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.

Return type

str

pathFrom(tree, sep='\\')

Retrieve the path from the given tree to this entry.

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.

Return type

str

suffix()

Retrieve the “last” extension of this entry.

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

Returns

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

or is directory.

Return type

str