执行对应脚本文件
import os
def get_all_images(project_path, output_folder):
for root, dirs, files in os.walk(project_path):
for file in files:
if file.endswith(".png") or file.endswith(".jpg") or file.endswith(".jpeg"):
file_path = os.path.join(root, file)
output_path = os.path.join(output_folder, file)
os.makedirs(os.path.dirname(output_path), exist_ok=True)
os.rename(file_path, output_path)
project_path = "/Users/saman0/Desktop/main/PZSwift/PZSwift/Assets.xcassets"
output_folder = "/Users/saman0/Desktop/temp"
get_all_images(project_path, output_folder)
但是上面那个脚本执行会把之前文件夹中的图片也跟着删除
下面这个就是复制图片到新文件夹中
import os
import shutil
def copy_all_images(project_path, output_folder):
for root, dirs, files in os.walk(project_path):
for file in files:
if file.endswith(".png") or file.endswith(".jpg") or file.endswith(".jpeg"):
file_path = os.path.join(root, file)
output_path = os.path.join(output_folder, file)
os.makedirs(os.path.dirname(output_path), exist_ok=True)
shutil.copy(file_path, output_path)
project_path = "/Users/saman0/Desktop/main/PZSwift/PZSwift/Assets.xcassets"
output_folder = "/Users/saman0/Desktop/haha"
copy_all_images(project_path, output_folder)