pyufunc.generate_unique_filename#

pyufunc.generate_unique_filename(filename, suffix_num=1)#

Generate a unique filename by adding a suffix number to the end of the filename.

This function is extremely useful when you want to save a file, but not sure if the file already exists.

Location:

pyufunc/util_pathio/_path.py

See also

create_unique_filename

Parameters:
  • filename (str | Path) – the filename to be validated

  • suffix_num (int) – Suffix number used when the filename already exists. Defaults to 1.

Returns:

validated filename

Return type:

str

Examples

>>> import pyufunc as uf
>>> uf.generate_unique_filename('./test.txt')
'C:/Users/Administrator/Desktop/test/test(1).txt'