# -*- 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 --批量重命名文件名的更多相关文章

  1. Python批量重命名 工具贴(一)

    说明 由于在处理图片数据和其他数据时,经常需要对数据进行批量重命名操作,每次使用时都需要重写,非常不便,因此记录下重命名代码方便后续使用. 文件结构说明 参数说明: path为输入路径 image_t ...

  2. python批量重命名【截取文件名前六个字符 】

    #!/usr/bin/python # -*- coding: UTF-8 -*- import os, sys # 打开文件 path = "/home/landv/Desktop/l/& ...

  3. 利用Python批量重命名一系列文件名杂乱的文件

    假设目录下面有这样一系列命令杂乱的文件: OPENFOAM -TRAINING- PART- #1.pdf OPENFOAM - TRAINING- PART- #2.pdf OPENFOAM- TR ...

  4. [经典] 使用Python批量重命名iPhone拍摄的照片-按照拍摄时间重命名

    #!/usr/bin/env python # -*- coding: utf-8 -*- ''' 批量修改照片文件名称的Python脚本程序. 遍历指定目录(含子目录)的照片文件,根据拍照时间将照片 ...

  5. Python批量重命名文件

    批量替换文件名中重复字符: # -*- coding: UTF-8 -*- import os path = raw_input("请输入文件夹路径:") oldname = ra ...

  6. 利用Python批量重命名文件夹下文件

    #!/usr/bin/python # -*- coding: UTF-8 -*- # -*- coding:utf8 -*- import os from string import digits ...

  7. Python批量重命名

    某无聊的下午的一个小需求 import os dirPath = r'' #路径 format = r'' #后缀 name = 0 for file in os.listdir(dirPath): ...

  8. python 批量重命名文件后缀

    # batch_file_rename.py # Created: 6th August 2012 ''' This will batch rename a group of files in a g ...

  9. python 批量重命名

    import osll=os.listdir(".")c=0for f in ll: c=c+1 os.rename(f,str(c)+".jpg")

随机推荐

  1. When to use static method in a java class

    First , please understand its feature : * no need to instantiate a instance, i.e. simply you can jus ...

  2. Python模块之: configobj(转)

    原来也有写过一篇文章Python模块之: ConfigParser 用来解析INI文件,但是在使用过程中存在一些问题.比如:1,不能区分大小写.2,重新写入的ini文件不能保留原有INI文件的注释.3 ...

  3. BOOST Converter Analog/Digital Adjusted Output Voltage TPS61045 MAX1932

    DIGITALLY ADJUSTABLE BOOST CONVERTER The TPS61045 is a high frequency boost converter with digitally ...

  4. mysql 监控工具

    zabbix和grafana是绝配.  pmm的prometheus太占资源了

  5. linux下关于压缩、解压相关的操作

    本文转自: http://alex09.iteye.com/blog/647128 很不错的linux下关于压缩.解压相关的操作,适合于linux初学者.   .tar  解包:tar xvf Fil ...

  6. Silverlight:《Pro Silverlight5》读书笔记 之 XAML

    XAML Properties and Events in XAML Simple Properties and Type Converters To bridge the gap between s ...

  7. JAVA Date超强工具类,可直接取代util.Date使用

    package net.maxt.util; import java.text.DateFormat; import java.text.ParseException; import java.tex ...

  8. 仿LOL项目开发第四天

    ---恢复内容开始--- 仿LOL项目开发第四天 by草帽 上节讲了几乎所有的更新版本的逻辑,那么这节课我们来补充界面框架的搭建的讲解. 我们知道游戏中的每个界面都有自己的一个类型:比如登陆界面,创建 ...

  9. POJ 2046 Gap 搜索- 状态压缩

    题目地址: http://poj.org/problem?id=2046 一道搜索状态压缩的题目,关键是怎样hash. AC代码: #include <iostream> #include ...

  10. kvm安装windows系统

    1.创建虚拟机镜像文件并指定大小(10G) [root@centos01 ~]# qemu-img create -f raw /opt/windows20031.raw 10G Formatting ...