# -*- 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. jQuery如何获取动态添加的元素

    1. 使用 on()方法        本质上使用了事件委派,将事件委派在父元素身上     自 jQuery 版本 1.7 起,on() 方法是 bind().live() 和 delegate() ...

  2. css中!important的优先级问题

    css中!important的优先级在主页面中写>在外部引用的css文件 之前我一直以为css的样式不管写在哪里只要加上!important那么它的优先级就是最高的,事实上并不是这样的,尤其在动 ...

  3. flush清空输入输出流

    #include <string.h> #include <stdio.h> #include <conio.h> #include <io.h> vo ...

  4. Js的在线代码编辑器:CodeMirror

    github地址:https://github.com/codemirror/CodeMirror/tree/master/demo 里面包含需要的js.css文件以及大量的示例 官网:https:/ ...

  5. 使用HttpClient发送请求接收响应

    1.一般需要如下几步:(1) 创建HttpClient对象.(2)创建请求方法的实例,并指定请求URL.如果需要发送GET请求,创建HttpGet对象:如果需要发送POST请求,创建HttpPost对 ...

  6. OpenCV学习(5) Mat的基本操作(2)

          本章我们学习一下Mat中的常用操作,因为在后面其它的教程中,我们经常要对图像进行各种处理,也要使用这些操作. 一. Mat的复制,就是从一个矩阵A,生成相关的另一个矩阵B. (1)使用赋值 ...

  7. 如何获取Android唯一标识(唯一序列号)

    有很多场景和需求你需要用到手机设备的唯一标识符. 在Android中,有以下几种方法获取这样的ID. 1. The IMEI: 仅仅只对Android手机有效: 1 2 TelephonyManage ...

  8. JSP学习笔记(一):JSP语法和指令

    一.语法 1.脚本程序的语法格式: 脚本程序可以包含任意量的Java语句.变量.方法或表达式,只要它们在脚本语言中是有效的. <% 代码片段 %> 2.中文编码问题 如果我们要在页面正常显 ...

  9. Notepad++中设置Windows、Unix、Mac三种行尾换行符格式间的转换

    (1)首先,要设置NotePad++能显示换行符,这个才干看到效果, 视图-->显示符号-->显示行尾符. {2}设置行尾符格式:编辑-->档案格式转换-->(可选Window ...

  10. [JS Compose] 7. Ensure failsafe combination using monoids

    monoids is a semi-group with a neutral element. A semigroup, it does not have an element to return s ...