重命名文件,Python/Jython [英] Rename files, Python/Jython

查看:90
本文介绍了重命名文件,Python/Jython的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个充满文件的目录,其中一些文件的名称带有&符.我想用&符号重命名所有文件,并用加号(+)替换每个&符号.我正在处理大约1万个文件.最好的方法是什么?

I have a directory full of files, some which have an ampersand in their names. I would like to rename all the files with ampersands and replace each ampersand with a plus (+). I am working with around 10k files. What would be the best method to do this?

推荐答案

import glob, os
for filename in glob.glob(os.path.join(yourPath, "*&*")):
   os.rename(filename, filename.replace('&','+'))

这篇关于重命名文件,Python/Jython的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆