python之学习类:python修改文件名
下面是对某文件夹下多个文件下指定文件换名字的实例(为了换名字,因为懒得手动改,折腾了一会搞出来的)
原理很简单,换文件名的话指定path就行 ,具体的自己看吧,仅供参考!
#-*- coding:utf-8 -*-
import os,sys
#=======================================
##对多个文件夹下的文件(夹)进行处理
#=======================================
def getdirNames(path):
dirNames = os.listdir(path)
return dirNames
def isDir(dirNames,path):
for item in dirNames:
dir = os.path.join(path,item)
if(os.path.isdir(dir)):
dirAddress.append(dir)
file = getdirNames(dir)
isDir(file,dir)
else:
if 'png' in item:
fileAddress.append(dir)
return fileAddress
#=======================================
##对某个文件夹下面的文件进行处理
#=======================================
def fil(filename):
mapdir = filename[-1:]
mapname = filename[:-2].replace('0','')
changename = mapname[::-1].zfill(8)[::-1]
rename = changename+'_'+mapdir
return rename
if __name__ == '__main__':
#此处添加需要转换名字的文件夹路径(文件夹下面可以有多个文件夹),【例如:在此我将“0103020202_0.png”转换成“13222000_0.jpg:】
path0 = r'F:\python\20100412\game\data\images\Object\World\Road'
dirAddress = []
fileAddress = []
dirNames = getdirNames(path0)
isDir(dirNames,path0)
print fileAddress
for i in range(len(fileAddress)):
&
相关文档:
#快速排序
def Partition(mylist, low, high):
tmp = mylist[low]
while low < high:
while low < high and mylist[high] >= tmp:
high = high - 1
if low < high:
mylist[low] = mylist[high]
low = low + 1
while low < hi ......
#!/usr/bin/env python
#coding=utf-8
def buildConnectionString(params):
return ":".join(["%s=%s" %(k, v) for k, v in params.items()])
if __name__ == "__main__":
myParams = {"server":"mpilgrim", \
&nbs ......
1. Building an Application with PyGTK and Glade
2. Creating a GUI using PyGTK and Glade
3. A Beginner's Guide to Using pyGTK and Glade
4. Is there a walkthrough on getting PyGTK2 and libglade2 to work on win32 ......
昨天在研究了几天PHP-GTK后,决定转向Python,因为Python具有多线程这个特点,在与系统交互方面也比较有优势,虽然我很喜欢PHP,PHP在网页方面也非常强大,但毕竟我不是搞网站开发的。
想下个Python吧,发现它居然被和谐了,太诡异了
唉,和谐有理,屏蔽无罪! ......