B站视频同款代码
# @author冷曦同学
import os
import shutil
org_path='E:上市公司年报整理前'
new_path='E:上市公司年报整理后'
for root,dirs,files in os.walk(org_path):#遍历文件夹
for name in files:
id_name=name.split('-')[0]#处理文件命
new_dir_path=new_path+'\'+id_name
if not os.path.exists(new_dir_path):#判断是否有文件夹,没有就创立
os.makedirs(new_dir_path)
old_file_path=os.path.join(root,name)#旧文件路径
new_file_path=new_dir_path+'\'+name#新文件路径
shutil.move(old_file_path,new_file_path)#移动文件



