import os import random import shutil def move_file(target_path, save_path, number): file_list = os.listdir(target_path) random.shuffle(file_list) file_list = file_list[:number] for file in file_list: target_file_path = os.path.join(target_path, file) save_file_path = os.path.join(save_path, file) shutil.move(target_file_path, save_file_path) if __name__ == '__main__': target_path = r'' save_path = r'' number = 10 move_file(target_path, save_path, number)
标签:__,target,python,list,文件夹,随机,file,path,save From: https://www.cnblogs.com/moon3496694/p/17223259.html