python 移动大于10M的文件至其他目录

#!/usr/bin/python
import os
import shutil
def move_files(path,new_path,size):
    for  root,dirs ,files  in os.walk(path):
        for  file in files:
            file_path=os.path.join(root,file)
            file_size=os.path.getsize(file_path)
            print file_path,file_size
            if file_size > size:
                shutil.move(file_path,new_path)




if  __name__ == '__main__':
    path='/home/xmc/'
    new_path='/opt'
    size='1024*1024*10'    #10M
    move_files(path,new_path,size)

     

 

posted @ 2019-05-07 16:16  xmc_2022  阅读(156)  评论(0)    收藏  举报