prevent_overwrite

imagepypelines.core.io.prevent_overwrite(filename, create_file=False)[source]

checks to see if a file or directory already exists and creates a new filename if it does. It can also create the file if specificed

when creating a file, this function assumes that if there is no file extension then it should create a directory

Note

This function creates unique filenames by creating them and checking their current existence. THIS CAN BE A SLOW PROCESS – it is much more efficient to keep track of filenames internally in your application

Parameters:
  • filename (str) – the full file or directory path to be overwrite protected
  • create_file (bool) – Default is False boolean indicating whether or not to create the file before returning
Returns:

the assuredly unique output filename

Return type:

str