FilenameParts¶
Sets filename parts with new values. |
|
|
Returns a |
Returns this name givers validator providing the file naming convention. |
|
Sets the value of a convention’s filename part. |
|
Disassembles the filename returning ANameGiver. |
|
The mandatory entity’s name which relates to multiple files. |
|
The sub id is the first branch of the identifier. |
|
The source id states, where this file came from. |
|
The group of variables (vargroup) contains meta attributes. |
|
Context of the file’s content. |
|
The common file extension with a leading dot. |
- class namefiles.FilenameParts(identifier: Optional[str] = None, sub_id: Optional[str] = None, source_id: Optional[str] = None, vargroup: Optional[List[str]] = None, context: Optional[str] = None, extension: Optional[str] = None, root_path: Optional[str] = None, **kwargs)¶
The filename parts implements the current standard file naming convention. The FilenameParts is the convinient tool to make a new filename based on the latest standard file naming convention.
- Parameters
identifier – The mandatory entity’s name which relates to multiple files. The identifier is the leading filename part.
sub_id – The sub id is the first branch of the identifier.
source_id – The source id states, where this file came from.
vargroup – The group of variables (vargroup) contains meta attributes.
context – Context of the file’s content. What is this about?
extension – The extension of this file. The extension states the files format or structure.
root_path – The files location.
Examples
The major entry point is the disassemble method, which returns the FilenameParts instance containing all filename parts based on the latest standard file naming convention.
>>> from namefiles import FilenameParts >>> sample_giver = FilenameParts.disassemble("A#NAME.txt") >>> sample_giver FilenameParts(root_path: ., identifier: A, extension: .txt, sub_id: NAME)
The FilenameParts mimics a Mapping and additionally providing the major filename parts as properties.
>>> sample_giver["identifier"] 'A' >>> sample_giver["sub_id"] 'NAME' >>> sample_giver.identifier 'A' >>> sample_giver.identifier = "Zebra" >>> sample_giver.identifier 'Zebra'
Either convert the instance to a string to get a filename (filepath)
>>> str(sample_giver) 'Zebra#NAME.txt'
or use the
FilenameParts.to_path()
method to receive apathlib.PurePath
.