def delete_last_string(input_file, output_file):
    with open(input_file, 'r') as f_in, open(output_file, 'w') as f_out:
        for line in f_in:

            parts = line.split()

            number = int(float(parts[-1]) * 1e6)

            f_out.write(str(number) + '\n')
            
def swap_lines(input_file, output_file):
    with open(input_file, 'r') as f_in, open(output_file, 'w') as f_out:
        for line in f_in:

            parts = line.split()

            f_out.write(parts[1] + ' ' + parts[0] + '\n')
def rename_lines(input_file, output_file):
    with open(input_file, 'r') as f_in, open(output_file, 'w') as f_out:
        for line in f_in:

            parts = line.split('/')

            filename = parts[-1]

            number_str = filename.split('_')[-1].split('.')[0]

            number = int(number_str)

            new_filename = '{:05d}.png'.format(number)
            new_line = '/'.join(parts[:-1]) + '/' + new_filename

            f_out.write(new_line +" "+ filename.split(' ')[-1])
import os
import shutil

def rename_images_in_txt(input_file, output_file):
    with open(input_file, 'r') as f:
        lines = f.readlines()
    
    with open(output_file, 'w') as f:
        for index, line in enumerate(lines):
            parts = line.split()
            new_image_name = f"images/{index:05d}.png"
            number = parts[1]
            f.write(f"{new_image_name} {number}\n")



# input_file = 'D:/2024/3DGS/PureEventFilter/data/dynamic_high_colmap_easy/image_timestamps_old.txt'

# output_file = "D:/2024/3DGS/PureEventFilter/data/dynamic_high_colmap_easy/image_timestamps_old2.txt"


# swap_lines(input_file, output_file)

# input_file = 'D:/2024/3DGS/PureEventFilter/data/dynamic_high_colmap_easy/image_timestamps_old2.txt'

# output_file = "D:/2024/3DGS/PureEventFilter/data/dynamic_high_colmap_easy/image_timestamps.txt"


# rename_lines(input_file, output_file)

# input_file = "D:/2024/3DGS/PureEventFilter/data/dynamic_high_colmap_easy/image_timestamps_old2.txt"

# output_file = "D:/2024/3DGS/PureEventFilter/data/dynamic_high_colmap_easy/image_timestamps_e2.txt"


# delete_last_string(input_file, output_file)


source_folder = 'D:/2024/3DGS/PureEventFilter/data/dynamic_high_colmap_easy/image_timestamps_old2.txt'
destination_folder = 'D:/2024/3DGS/PureEventFilter/data/dynamic_high_colmap_easy/image_timestamps.txt'
rename_images_in_txt(source_folder, destination_folder)