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")
随机推荐
- zabbix install
Auth: Jin Date: 20140714 用了5 6年的监控工具 http://zabbix.org/wiki/InstallOnCentOS_RHEL Server Install yum ...
- ubuntu systemtap-sdt-dev
http://kr.archive.ubuntu.com/ubuntu/pool/universe/s/systemtap/systemtap-sdt-dev_3.0-7_amd64.deb
- u3d移动游戏优化规范
1.顶点性能一般来说,如果您想在iPhone 3GS或更新的设备上每帧渲染不超过40,000可见点,那么对于一些配备 MBX GPU的旧设备(比如,原始的 iPhone,如 iPhone 3g和 iP ...
- 独立成分分析 与 功能连接之间的关联尝试 by 张高燕
在处理fMRI数据时,使用空间ICA的方法. 将一个四维的fMRI数据分解为空间pattern与时间序列的乘积. //这里的pattern=component 其中每一pattern的时间序列 ...
- SHA1算法实现及详解
1 SHA1算法简介 安全哈希算法(Secure Hash Algorithm)主要适用于数字签名标准(Digital Signature Standard DSS)里面定义的数字签名算法(Digit ...
- Python学习(八)异常处理
Python 异常处理 程序出错时,会抛出异常,这想必在之前学习过程中已经见过不少. 这边具体说明下Python 的标准异常.如何捕捉异常.抛出异常 以及自定义异常. python 标准异常 我们先来 ...
- go语言基础之工程管理和工作区介绍
1.工程管理 在实际的开发工作中,直接调用编译器进行编译和链接的场景是少而又少,因为在工程中不会简单到只有一个源代码文件,且源文件之间会有相互的依赖关系.如果这样一个文件一个文件逐步编译,那不亚于一场 ...
- IP数字,数字IP
DECLARE @ip VARCHAR(60)='113.118.138.159'DECLARE @ip_int BIGINT=[dbo].[f_IP2Int](@ip) SELECT [IPstar ...
- hadoop中典型Writable类详解
本文地址:http://www.cnblogs.com/archimedes/p/hadoop-writable.html,转载请注明源地址. Hadoop将很多Writable类归入org.apac ...
- J2EE 中 用 El表达式 和 Jsp 方式 取得 URL 中的参数方法
使用 el表达式方法: var urlParamValue = "${param.urlVarName}"; 使用 Jsp 表达式 var urlParamValue2 = &qu ...