syntactic.syntactic_rename

syntactic.syntactic_rename(path: str | list[str], recursive: bool = False, fun: str = 'kebab_case', quiet: bool = False, dry_run: bool = False, lowercase_ext: bool = False) dict[str, list[str]]

Rename files and/or directories using a syntactic naming function.

Parameters:
  • path (str or list of str) – A file path, directory path, or list of paths. When a single directory is given, its contents are renamed.

  • recursive (bool) – If True, recurse into directories.

  • fun (str) – Naming function to use.

  • quiet (bool) – Suppress output messages.

  • dry_run (bool) – Preview changes without renaming.

  • lowercase_ext (bool) – If True, also convert the file extension to lowercase.

Returns:

Mapping with keys "from" and "to", each a list of absolute paths in matching order.

Return type:

dict

Examples

>>> import tempfile
>>> d = tempfile.mkdtemp()
>>> path = f"{d}/mRNA Extraction.pdf"
>>> _ = open(path, "w").close()
>>> result = syntactic_rename(path, fun="kebab_case", quiet=True)
>>> result["to"][0].endswith("mrna-extraction.pdf")
True
>>> import os
>>> os.remove(result["to"][0])
>>> os.rmdir(d)