GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing www.cnblogs.com — python文件批量改名 - 金明爱python - 博客园 python文件批量改名
python批量改名
python对文件进行批量改名用到的是os模块中的listdir方法和rename方法。 os.listdir(dir) :获取指定目录下的所有子目录和文件名 os.rename(原文件名,新文件名):对文件或目录改名
把混乱的文件名改成有序的文件名
import os path=input('请输入文件路径(结尾加上/):') #获取该目录下所有文件,存入列表中 f=os.listdir(path) n=0 for i in f: #设置旧文件名(就是路径+文件名) oldname=path+f[n] #设置新文件名 newname=path+'a'+str(n+1)+'.JPG' #用os模块中的rename方法对文件改名 os.rename(oldname,newname) print(oldname,'======>',newname) n+=1
公告 |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |