今天为了批量处理下电脑里的文件,拿Python实现了遍历文件夹内的文件,并修改文件名字的脚本。
在代码中 rootdir 变量是需要遍历的目录,大家可以自行更改。
import os
import os.path
rootdir = "E:\wamp\www"
for parent,dirnames,filenames in os.walk(rootdir):
for dirname in dirnames:
print "parent is:" + parent
print "dirname is" + dirname
for filename in filenames:
print "parent is:" + parent
print "filename is:" + filename
print "flename replace:" + filename.replace("_IObitDel","")
print "the full name of the file is:" + os.path.join(parent,filename)
print "the full name of the file is:" + os.path.join(parent,filename.replace("_IObitDel",""))
os.rename(os.path.join(parent,filename),os.path.join(parent,filename.replace("_IObitDel","")))
文章的脚注信息由WordPress的wp-posturl插件自动生成
微信扫一扫,打赏作者吧~![[整理]how to run flask with pyqt5](http://www.jyguagua.com/wp-content/themes/begin/timthumb.php?src=http://www.jyguagua.com/wp-content/uploads/2021/03/pyqt_flask.png&w=280&h=210&zc=1)
![[已解决]LINK : fatal error LNK1158: cannot run 'rc.exe' 错误的解决办法](http://www.jyguagua.com/wp-content/themes/begin/timthumb.php?src=http://www.jyguagua.com/wp-content/uploads/2021/02/Snipaste_2021-02-17_15-18-26-1024x505.png&w=280&h=210&zc=1)
![[已解决]Python扩展模块 error: Unable to find vcvarsall.bat](http://www.jyguagua.com/wp-content/themes/begin/timthumb.php?src=http://www.jyguagua.com/wp-content/uploads/2020/11/Snipaste_2020-11-19_10-01-38.png&w=280&h=210&zc=1)
![[整理]PyQt画圆,动态变色](http://www.jyguagua.com/wp-content/themes/begin/timthumb.php?src=http://www.jyguagua.com/wp-content/uploads/2020/08/drawCircle.gif&w=280&h=210&zc=1)