python 批量文件管理
2021/10/21 1:09:37
本文主要是介绍python 批量文件管理,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
先上代码,之后再补充
import os import glob import shutil dir='....' if not os.path.exists(dir+'training'): os.mkdir(dir+'training') if not os.path.exists(dir+'testing'): os.mkdir(dir+'testing') for i in range(1,38): a='person{}'.format(i) file_name=dir+'training/'+a if not os.path.exists(file_name): os.mkdir(file_name) for i in range(38,41): a='person{}'.format(i) file_name=dir+'testing/'+a if not os.path.exists(file_name): os.mkdir(file_name) for j in range(1,10): s='s0{}*'.format(j) t='person{}'.format(j) s_file_name=dir+s t_file_name=dir+'training'+'/'+t+'/' for data in glob.glob(s_file_name): if not os.path.isdir(data): shutil.move(data,t_file_name) for j in range(10,38): s='s{}*'.format(j) t='person{}'.format(j) s_file_name=dir+s t_file_name=dir+'training'+'/'+t+'/' for data in glob.glob(s_file_name): if not os.path.isdir(data): shutil.move(data,t_file_name) for j in range(38,41): s='s{}*'.format(j) t='person{}'.format(j) s_file_name=dir+s t_file_name=dir+'testing'+'/'+t+'/' for data in glob.glob(s_file_name): if not os.path.isdir(data): shutil.move(data,t_file_name)
这篇关于python 批量文件管理的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-14获取参数学习:Python编程入门教程
- 2024-11-14Python编程基础入门
- 2024-11-14Python编程入门指南
- 2024-11-13Python基础教程
- 2024-11-12Python编程基础指南
- 2024-11-12Python基础编程教程
- 2024-11-08Python编程基础与实践示例
- 2024-11-07Python编程基础指南
- 2024-11-06Python编程基础入门指南
- 2024-11-06怎么使用python 计算两个GPS的距离功能-icode9专业技术文章分享