python 将大批文件 分组移动到文件夹中

2018-08-01

23

0

技术:python2.7 

运行环境:python2.7 + windows 10

demo功能:提供一个python 移动文件的代码demo

源代码

import os
import os.path
import shutil

folder_capacity = 5


def copy_files(src_dir, dest_dir):
    count = 0
    current_folder = ''

    for item in os.listdir(src_dir):
        abs_item = os.path.join(src_dir, item)
        if os.path.isfile(abs_item):
            count += 1
            if count % folder_capacity == 1:
                current_folder = os.path.join(dest_dir, str(count / folder_capacity))
                os.mkdir(current_folder)

            shutil.move(abs_item, os.path.join(current_folder, item))
            # open(os.path.join(current_folder, item), 'wb').write(open(abs_item, 'rb').read())


copy_files(r'D:\\mock-jsons-a', r'D:\\mock-jsons-b')

步骤2

xxxxxxxxxxxxxxxxxxxxxxx

步骤3

xxxxxxxxxxxxxxxxxxxxxxx

步骤4

xxxxxxxxxxxxxxxxxxxxxxx

步骤5

xxxxxxxxxxxxxxxxxxxxxxx

欢迎添加微信,互相学习↑↑↑ -_-

发表评论

全部评论:0条

白老虎

programming is not only to solve problems, ways to think