import os import glob def get_image_filenames(folder_path, output_file): # Define the image file extensions you want to include image_extensions = ['*.jpg', '*.jpeg', '*.png', '*.gif', '*.bmp', '*.tiff'] # Create an empty list to store filenames image_filenames = [] # Iterate over each extension and gather the filenames for extension in image_extensions: image_filenames.extend(glob.glob(os.path.join(folder_path, extension))) # Write the filenames to the output file with open(output_file, 'w') as file: for filename in image_filenames: file.write(os.path.basename(filename) + '\n') # Specify the folder containing images and the output text file folder_path = 'D:\Ardha\Kerja\AISensum\ROX\Input\Task 1' output_file = 'image_filenames.txt' # Call the function to get image filenames and save them to a text file get_image_filenames(folder_path, output_file) print(f"Image filenames have been saved to {output_file}")