# -*- 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. debian8上安装pyspider - pyspider中文文档 - pyspider中文网

    debian8上安装pyspider - pyspider中文文档 - pyspider中文网   #apt-get install python python-dev python-distribu ...

  2. SD卡 TF卡 接口引脚定义

  3. XDroidRequest网络请求框架,新开源

    XDroidRequest 是一款网络请求框架,它的功能也许会适合你.这是本项目的第三版了,前两版由于扩展性问题一直不满意,思考来 思考去还是觉得Google的Volley的扩展性最强,于是借鉴了Vo ...

  4. 通过 WCF 实现点对点文件共享 z

    下载免费的项目源代码 下载项目的数据库 目录 简介 背景 为什么是WCF? WCF历史简述 WCF基础 点对点概念 代码分析(它是怎么工作的) 核心转化引擎层 下载管理层 服务层 代码的使用(如何运行 ...

  5. 设计原则:小议 SPI 和 API

    背景 第一次听说 SPI 是阅读<软件框架设计的艺术>,以后陆续在 Log4Net 和 Quartz.Net中发现了以这种形式组织代码的方式,本位给出为什么要区分 SPI 和 API 的一 ...

  6. appium+python自动化24-滑动方法封装(swipe)

    swipe介绍 1.查看源码语法,起点和终点四个坐标参数,duration是滑动屏幕持续的时间,时间越短速度越快.默认为None可不填,一般设置500-1000毫秒比较合适. swipe(self, ...

  7. Xcode 安装插件管理器

    https://github.com/alcatraz/Alcatraz运行之后, load bundle, 然后window就有pakagegemanage. 下载如下插件: 自动导入插件

  8. ICLR 2014 International Conference on Learning Representations深度学习论文papers

    ICLR 2014 International Conference on Learning Representations Apr 14 - 16, 2014, Banff, Canada Work ...

  9. #include &lt;NOIP2010 Junior&gt; 三国游戏 ——using namespace wxl;

    题目描述 小涵很喜欢电脑游戏,这些天他正在玩一个叫做<三国>的游戏. 在游戏中,小涵和计算机各执一方,组建各自的军队进行对战.游戏中共有 N 位武将(N为偶数且不小于 4),任意两个武将之 ...

  10. iOS:转载FMDB文档

    来自会员pengtao的分享:(原文:https://github.com/ccgus/fmdb) 由于FMDB是建立在SQLite的之上的,所以你至少也该把这篇文章从头到尾读一遍.与此同时,把SQL ...