Skip to main content

suffixes

Function suffixes 

Source
pub fn suffixes(path: &str, fmt: PathFormat) -> Vec<String>
Expand description

Get all suffixes (like Python’s PurePath.suffixes). “file.tar.gz” → [“.tar”, “.gz”] Get all suffixes (extensions) of the file name.

Matches Python pathlib’s algorithm:

  name = self.name
  if name.endswith('.'):
      return []
  name = name.lstrip('.')
  return ['.' + suffix for suffix in name.split('.')[1:]]

Notable corollaries:

  • Trailing-dot names have no suffixes (foo.[]).
  • Names that consist entirely of leading dots (., .., ...) yield [] because lstrip('.') produces the empty string.
  • .tar.gz (a name that is itself a suffix-looking filename) yields ['.gz'], not ['.tar', '.gz'] — the leading-dot prefix is stripped before splitting.
  • ..foo yields [] even though suffix returns .foo, because lstrip('.') produces 'foo' which has no inner dot. This is a pathlib quirk we preserve for parity.