python脚本实现文件的批量移动、复制,以及删除指定后缀
来源:互联网 发布:java实时读取log文件 编辑:程序博客网 时间:2024/06/08 05:59
话不多说,直接上代码。
import osimport os.pathfolder_capacity = 10000def 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) open(os.path.join(current_folder, item), 'wb').write(open(abs_item, 'rb').read()) if count<20000: continue else: breakdef copy_file(source_dir,target_dir): count=0 for item in os.listdir(source_dir): source_files=os.path.join(source_dir,item) if not os.path.exists(target_dir): os.mkdir(target_dir) target_files = os.path.join(target_dir,item) count +=1 open(target_files,'wb').write(open(source_files,'rb').read()) if count>1000: break def move_file(source_dir,target_dir): count = 0 for item in os.listdir(source_dir): source_files=os.path.join(source_dir,item) if not os.path.exists(target_dir): os.mkdir(target_dir) target_files = os.path.join(target_dir,item) count +=1 open(target_files,'wb').write(open(source_files,'rb').read()) os.remove(source_files) if count>=1041: breakif __name__ =='__main__': move_file('~/alexnet/data_light/lighter','~/alexnet/data_light/light')
python批量删除指定后缀及后缀字符
#!/usr/bin/pythonimport osfor root , dirs, files in os.walk('.\hei'): #file =os.path.splitext(files) nums= 0 for name in files: if name.endswith(".jpg"): #if name[:-4].endswith("idcardimage"): nums +=1 print("start") os.remove(os.path.join(root, name)) print ("Delete File: " + os.path.join(root, name)) if nums >1: break print("the sum of remove items is:\n%d" %(nums))print ("over!")#后面if语句是删除文件名指定字符后缀,这里指定字符是"idcardimage",之后的if语句是用来设置删除文件的个数的,最后输出删除文件数量。
阅读全文
0 0
- python脚本实现文件的批量移动、复制,以及删除指定后缀
- Linux 批量删除指定后缀的文件
- 批量删除指定后缀文件
- linux下批量删除指定后缀的文件
- linux下批量删除指定后缀的文件
- python脚本编程:批量复制或删除文件
- 快速批量删除指定类型文件脚本
- shell 批量删除指定文件 脚本
- python脚本删除指定路径下指定类型的文件
- python遍历删除指定后缀文件
- Python 批量删除文件夹下面指定类型的所有文件
- Python 批量删除文件夹下面指定类型的所有文件
- Python脚本批量删除特定后缀名的文件
- 批量删除相同后缀的文件
- 批量复制指定文件
- python 文件删除 移动 复制等操作
- 批处理递归删除指定后缀的文件
- Python 实现文件复制、删除
- caffe 微调网络模型
- [jbb0523整理]压缩感知中的数学知识:线性方程组的解
- BZOJ1096[ZJOI2007]仓库建设
- 在IDEA 2017中导入Eclipse项目
- MarkdownPad 2使用小技巧
- python脚本实现文件的批量移动、复制,以及删除指定后缀
- deep learning for face detection
- (79)蓝图中的结构体变量
- 另类的Linq To Sql —— CoolEntity开始开发 (一) 添加引用
- ES6语法(7)
- 基于ZoomEye钟馗之眼API的python脚本
- 消息队列基本知识
- 【设计模式】—— 解释器模式Interpret
- 配置xml