Spaces:
Sleeping
Sleeping
File size: 987 Bytes
39887c3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
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}")
|