factorize code with get_file_name()