python --批量重命名文件名
# -*- coding: utf-8 -*-
import os
path = "d:\\curl\data\\"
for file in os.listdir(path):
print file
if(os.path.isfile(os.path.join(path,file))==True):
if file.find('.')>0:
newname="new_"+file
os.rename(os.path.join(path,file),os.path.join(path,newname))
print file,'ok'
代码2:
# -*- coding: utf-8 -*-
import os def BatchRename(path,pattern):
os.chdir(path)
fileList=os.listdir(path)
dotIndex = pattern.rfind('.')
fileName = pattern[ : dotIndex]
fileExt = pattern[dotIndex : ]
genNum = 0
for fileItem in fileList:
fileFullName = fileName + '_' + str(genNum) + fileExt
os.rename(fileItem, fileFullName)
print (fileItem + ' => ' + fileFullName)
genNum += 1 if __name__ == '__main__':
BatchRename("d:\\curl\\data","test.log")
代码3:
import os
os.chdir("d:\\curl\\data")
for file in os.listdir("d:\\curl\\data"):
print file
if(os.path.splitext(file)[1] == ".log"):
print "yes"
os.rename(file, os.path.splitext(file)[0]+".jpg")
python --批量重命名文件名的更多相关文章
- Python批量重命名 工具贴(一)
说明 由于在处理图片数据和其他数据时,经常需要对数据进行批量重命名操作,每次使用时都需要重写,非常不便,因此记录下重命名代码方便后续使用. 文件结构说明 参数说明: path为输入路径 image_t ...
- python批量重命名【截取文件名前六个字符 】
#!/usr/bin/python # -*- coding: UTF-8 -*- import os, sys # 打开文件 path = "/home/landv/Desktop/l/& ...
- 利用Python批量重命名一系列文件名杂乱的文件
假设目录下面有这样一系列命令杂乱的文件: OPENFOAM -TRAINING- PART- #1.pdf OPENFOAM - TRAINING- PART- #2.pdf OPENFOAM- TR ...
- [经典] 使用Python批量重命名iPhone拍摄的照片-按照拍摄时间重命名
#!/usr/bin/env python # -*- coding: utf-8 -*- ''' 批量修改照片文件名称的Python脚本程序. 遍历指定目录(含子目录)的照片文件,根据拍照时间将照片 ...
- Python批量重命名文件
批量替换文件名中重复字符: # -*- coding: UTF-8 -*- import os path = raw_input("请输入文件夹路径:") oldname = ra ...
- 利用Python批量重命名文件夹下文件
#!/usr/bin/python # -*- coding: UTF-8 -*- # -*- coding:utf8 -*- import os from string import digits ...
- Python批量重命名
某无聊的下午的一个小需求 import os dirPath = r'' #路径 format = r'' #后缀 name = 0 for file in os.listdir(dirPath): ...
- python 批量重命名文件后缀
# batch_file_rename.py # Created: 6th August 2012 ''' This will batch rename a group of files in a g ...
- python 批量重命名
import osll=os.listdir(".")c=0for f in ll: c=c+1 os.rename(f,str(c)+".jpg")
随机推荐
- Lower dc/dc-converter ripple by using optimum capacitor hookup
Low-ripple-voltage positive-to-negative dc/dc converters find use in many of today's high- frequency ...
- The New Virtual List Box in Delphi 6 - lbVirtual lbVirtualOwnerDraw
http://users.atw.hu/delphicikk/listaz.php?id=2471&oldal=52 Problem/Question/Abstract: What are t ...
- Struts2的ActionError&ActionMessage示例
本教程显示使用Struts2的 ActionError 和 ActionMessage 类. 1. ActionError – 是用来发送错误信息反馈给用户 - 通过 <s:actionerro ...
- CMAKE MYSQL
http://www.blogjava.net/kelly859/archive/2012/09/04/387005.html
- 【java】【mysql】存储微信表情emoji表情
java.sql.SQLException: Incorrect string value: '\xF0\x9F\x92\x94' for colum n 'name' at row 1 at com ...
- .NET:CLR via C# The CLR’s Execution Model
The CLR’s Execution Model The core features of the CLR memory management. assembly loading. security ...
- msgrcv,msgsnd进程通信,消息的发送和接收
//进程通信,消息的发送和接收 //client.c #include <unistd.h> #include <sys/types.h> #include <sys/s ...
- Python学习(九)IO 编程 —— 文件读写
Python 文件读写 Python内置了读写文件的函数,用法和C是兼容的.本节介绍内容大致有:文件的打开/关闭.文件对象.文件的读写等. 本章节仅示例介绍 TXT 类型文档的读写,也就是最基础的文件 ...
- awk排序作业
输入:给定一个hotelinfo文件,文件格式如下: shanghai_city_7208 上海全季酒店淮海路店 shanghai_city_14744 锦江之星上海金山城市沙滩店 ...
- Qt 事件处理机制 (下篇)
继续我们上一篇文章继续介绍,Qt 事件处理机制 (上篇) 介绍了Qt框架的事件处理机制:事件的产生.分发.接受和处理,并以视窗系统鼠标点击QWidget为例,对代码进行了剖析,向大家分析了Qt框架如何 ...