首页 > 编程语言 >python选出一定数量的随机文件到某个文件夹

python选出一定数量的随机文件到某个文件夹

时间:2023-03-16 16:57:12浏览次数:40  
标签:__ target python list 文件夹 随机 file path save

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

相关文章