FilenameParts

namefiles.FilenameParts.set_parts(…)

Sets filename parts with new values.

namefiles.FilenameParts.to_path([root_path])

Returns a pathlib.Path of the declared filename parts.

namefiles.FilenameParts.get_filename_validator()

Returns this name givers validator providing the file naming convention.

namefiles.FilenameParts.set_name_part(…)

Sets the value of a convention’s filename part.

namefiles.FilenameParts.disassemble(…)

Disassembles the filename returning ANameGiver.

namefiles.FilenameParts.identifier

The mandatory entity’s name which relates to multiple files.

namefiles.FilenameParts.sub_id

The sub id is the first branch of the identifier.

namefiles.FilenameParts.source_id

The source id states, where this file came from.

namefiles.FilenameParts.vargroup

The group of variables (vargroup) contains meta attributes.

namefiles.FilenameParts.context

Context of the file’s content.

namefiles.FilenameParts.extension

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.

  • contextContext 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 a pathlib.PurePath.