fdutils/files.py
def name_if_file_exists(full_path_filename, add_index=False):
    """ Checks if the filename (full path) exists and add a timestamp if it does or an index.
        It does not change the name of an existing file, this will usually be used as the name of file

    Args:
        add_index (bool):
        full_path_filename (str):

    Returns:
        str: the new name for the file if there was a file with the same name, if not, return the same full_path_filename
    """
    if not os.path.exists(full_path_filename):
        return full_path_filename

    new_full_path_filename = full_path_filename
    tries = 0

    while os.path.exists(new_full_path_filename) and tries < 10:
        if add_index:
            new_full_path_filename = get_filename_indexed(new_full_path_filename)
        else:
            new_full_path_filename = get_filename_timestamped(full_path_filename)

        log.debug('File already exists. Will check ' + new_full_path_filename)

        tries += 1

    if tries >= 10:
        raise Exception('There must be some racing condition as we tried using 10 different timestamp and '
                        'they did not work. Check your code for any threading/multiprocess issue !!')

    return new_full_path_filename
 Checks if the filename (full path) exists and add a timestamp if it does or an index.
        It does not change the name of an existing file, this will usually be used as the name of file

    Args:
        add_index (bool):
        full_path_filename (str):

    Returns:
        str: the new name for the file if there was a file with the same name, if not, return the same full_path_filename
    
Checks if the filename (full path) exists and add a timestamp if it does or an index.
It does not change the name of an existing file, this will usually be used as the name of file
Checks if the filename ( full path ) exists and add a timestamp if it does or an index . It does not change the name of an existing file this will usually be used as the name of file
def name_if_file_exists(full_path_filename, add_index=False):
    if not os.path.exists(full_path_filename):
        return full_path_filename
    new_full_path_filename = full_path_filename
    tries = 0
    while os.path.exists(new_full_path_filename) and tries < 10:
        if add_index:
            new_full_path_filename = get_filename_indexed(new_full_path_filename)
        else:
            new_full_path_filename = get_filename_timestamped(full_path_filename)
        log.debug('File already exists. Will check ' + new_full_path_filename)
        tries += 1
    if tries >= 10:
        raise Exception('There must be some racing condition as we tried using 10 different timestamp and '
                        'they did not work. Check your code for any threading/multiprocess issue !!')
    return new_full_path_filename
def name_if_file_exists ( full_path_filename , add_index = False ) : if not os . path . exists ( full_path_filename ) : return full_path_filename new_full_path_filename = full_path_filename tries = 0 while os . path . exists ( new_full_path_filename ) and tries < 10 : if add_index : new_full_path_filename = get_filename_indexed ( new_full_path_filename ) else : new_full_path_filename = get_filename_timestamped ( full_path_filename ) log . debug ( 'File already exists. Will check ' + new_full_path_filename ) tries += 1 if tries >= 10 : raise Exception ( 'There must be some racing condition as we tried using 10 different timestamp and ' 'they did not work. Check your code for any threading/multiprocess issue !!' ) return new_full_path_filename
Checks if the filename (full path) exists and add a timestamp if it does or an index.
Checks if the filename ( full path ) exists and add a timestamp if it does or an index .
""" Checks if the filename (full path) exists and add a timestamp if it does or an index.
        It does not change the name of an existing file, this will usually be used as the name of file

    Args:
        add_index (bool):
        full_path_filename (str):

    Returns:
        str: the new name for the file if there was a file with the same name, if not, return the same full_path_filename
    """
the new name for the file if there was a file with the same name, if not, return the same full_path_filename
the new name for the file if there was a file with the same name if not return the same full_path_filename
str
full_path_filename
None
add_index
None