1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| import os import tinify
tinify.key = "XXX" def get_all_files_in_folder(folder_path): files = [] for root, dirs, filenames in os.walk(folder_path): for filename in filenames: file_path = os.path.join(root, filename) files.append(file_path) return files
folder_path = r'D:\...' file_list = get_all_files_in_folder(folder_path) for file in file_list: source = tinify.from_file(file) source.to_file(file) print(file, "finished.") print("All finished!")
|