def merge_all_in_folder(folder, ext='<STR_LIT>',<EOL>dynamic_imports=None,<EOL>storage_service=None,<EOL>force=False,<EOL>ignore_data=(),<EOL>move_data=False,<EOL>delete_other_files=False,<EOL>keep_info=True,<EOL>keep_other_trajectory_info=True,<EOL>merge_config=True,<EOL>backup=True):
in_dir = os.listdir(folder)<EOL>all_files = []<EOL>for file in in_dir:<EOL><INDENT>full_file = os.path.join(folder, file)<EOL>if os.path.isfile(full_file):<EOL><INDENT>_, extension = os.path.splitext(full_file)<EOL>if extension == ext:<EOL><INDENT>all_files.append(full_file)<EOL><DEDENT><DEDENT><DEDENT>all_files = sorted(all_files)<EOL>trajs = []<EOL>for full_file in all_files:<EOL><INDENT>traj = load_trajectory(index=-<NUM_LIT:1>,<EOL>storage_service=storage_service,<EOL>filename=full_file,<EOL>load_data=<NUM_LIT:0>,<EOL>force=force,<EOL>dynamic_imports=dynamic_imports)<EOL>trajs.append(traj)<EOL><DEDENT>first_traj = trajs.pop(<NUM_LIT:0>)<EOL>first_traj.f_merge_many(trajs,<EOL>ignore_data=ignore_data,<EOL>move_data=move_data,<EOL>delete_other_trajectory=False,<EOL>keep_info=keep_info,<EOL>keep_other_trajectory_info=keep_other_trajectory_info,<EOL>merge_config=merge_config,<EOL>backup=backup)<EOL>if delete_other_files:<EOL><INDENT>for file in all_files[<NUM_LIT:1>:]:<EOL><INDENT>os.remove(file)<EOL><DEDENT><DEDENT>return first_traj<EOL>
Merges all files in a given folder.

    IMPORTANT: Does not check if there are more than 1 trajectory in a file. Always
    uses the last trajectory in file and ignores the other ones.

    Trajectories are merged according to the alphabetical order of the files,
    i.e. the resulting merged trajectory is found in the first file
    (according to lexicographic ordering).

    :param folder: folder (not recursive) where to look for files
    :param ext: only files with the given extension are used
    :param dynamic_imports: Dynamic imports for loading
    :param storage_service: storage service to use, leave `None` to use the default one
    :param force: If loading should be forced.
    :param delete_other_files: Deletes files of merged trajectories

    All other parameters as in `f_merge_many` of the trajectory.

    :return: The merged traj