os模块大概是用来操作系统的函数,如
os.getcwd() 是返回当前工作目录的函数,getcwd 应该是 get current work directory的意思。
os.renames(old, new) 是对目录、文件进行重命名的函数
对文件进行批量重命名的小程序:
import os
def rename():
path=pathpy
count=101
## path='C:\\Users\\lenovo\\Desktop\\new'
filelist=os.listdir(path)#该文件夹下所有的文件(包括文件夹)
for files in filelist:#遍历所有文件
Olddir=os.path.join(path,files)#原来的文件路径
#if os.path.isdir(Olddir):#如果是文件夹则跳过
# continue
## if Olddir==os.path.join(path,'*.py'):
if files.endswith(".py"):
continue
filename=os.path.splitext(files)[0]#文件名
filetype=os.path.splitext(files)[1]#文件扩展名
Newdir=os.path.joi