import os标签:文件,abs,file,pdf,path,拷贝,os,目录 From: https://www.cnblogs.com/yuwanbai/p/17006381.html
import shutil
data = os.walk(r'D:\a\b')
DPATH = r'D:\pdf_file'
for path,file_dir,file_list in data:
#print(path,file_list)
for file_name in file_list:
file_abs_path = os.path.join(path,file_name)
#print(file_abs_path)
ext = file_abs_path.strip().rsplit('.',1)[-1]
to_file_path = os.path.join(DPATH,file_name)
if ext == 'pdf':
# print(file_abs_path,'--->',to_file_path)
# shutil.copy(file_abs_path,to_file_path)#复制
#os.system(f'attrib -r {file_abs_path}')#删除文件的只读权限
#os.remove(file_abs_path)#删除,删除文件报错需要执行上一步;