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)
python选出一定数量的随机文件到某个文件夹的相关教程结束。
本文地址:
https://www.ufcn.cn/tutorials/2650714.html
如非特殊说明,本站内容均来自于网友自主分享,概不代表本站观点,如有任何问题我们都将在收到反馈后的第一时间进行处理!