def dir2fn(ofn, ifn, suffix) -> Union[None, Path]:
if not ofn:  <EOL><INDENT>return None<EOL><DEDENT>ofn = Path(ofn).expanduser()<EOL>ifn = Path(ifn).expanduser()<EOL>assert ifn.is_file()<EOL>if ofn.suffix == suffix:  <EOL><INDENT>pass<EOL><DEDENT>else:  <EOL><INDENT>assert ofn.is_dir(), f'<STR_LIT>'<EOL>ofn = ofn / ifn.with_suffix(suffix).name<EOL><DEDENT>try:<EOL><INDENT>assert not ofn.samefile(ifn), f'<STR_LIT>'<EOL><DEDENT>except FileNotFoundError:  <EOL><INDENT>pass<EOL><DEDENT>return ofn<EOL>
ofn = filename or output directory, to create filename based on ifn
ifn = input filename (don't overwrite!)
suffix = desired file extension e.g. .h5