#法一 import os path = "C://Python34//" for file in os.listdir(path): if os.path.isfile(os.path.join(path,file))==True: if file.find('.')<0: newname=file+'.jpg' os.rename(os.path.join(path,file),os.path.join(path,newname)) #法二 import os import glob path = "C://Python34//" for infile in glob.glob( os.path.join(path, '*.gif') ): for i in range (1,21): index_symbol = "_" + str(i) + "_" if index_symbol in infile: newfile = infile newfile = newfile.replace(index_symbol, str(i)); os.rename(infile, newfile) print (infile)
Python批量重命名指定目录下文件的两种方法
转载本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
上一篇:地道的 Python(二)
下一篇:设备驱动--中断开关执行的匹配
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
SpringBoot优雅捕捉异常的两种方法
SpringBoot优雅捕捉异常的两种方法
SpringBoot 异常处理 @ControllerAdvice @ExceptionHandler -
批量文件重命名的方法
批量文件重命名的方法
重命名 指定目录 文件复制 -
python批量重命名文件 python 批量重命名文件夹
我在图像处理时,遇到某些函数读路径不能有中文名,比如opencv。当然有其他更方便的解决方法。我这里直接重命名文件,也挺快的。
python批量重命名文件 python 重命名 文件名 文件路径