def parse_dir(dirname):
    """
    Hack to remove '/path/to/folder/untitled/' error from QTFileDialog where /untitled/ gets appended by default
    This happens when you select OK in in the getExistingDirectory dialog without manually selecting a directory
    Essentially you want to say OK to the default directory but for some reason /untitled/ gets added to the path

    :param dirname: string path to directory delimited by /
    :return: string path to directory delimited by / without .../untitled/... if it exists

    :Test Cases:
        x = '/User/Test/Desktop/'
        y = '/User/Test/untitled/Desktop/'
        z = '/untitled/User/Test/Desktop/'

        all will return the string '/User/Test/Desktop'

    :Note: If this will cause problems if the User actually has data stored in a path with a folder
           called untitled intentionally
    """
    splt = dirname.split('/')
    if 'untitled' in splt:
        index = splt.index('untitled')
        del splt[index]
        print('Warning: detected .../untitled/... somewhere in path')
        print(
            'This is often caused by an error in the QFileDialog implementation.'
            )
        print('Attempting to fix path automatically ...')
    return '/'.join(splt)
