python 去掉文件后缀名,python 删除后缀名文件
大家好,又见面了,我是你们的朋友全栈君。
Note:print语句供test 用
#!/usr/bin/python
import os, re, time, sys
import os.path
import string
filter_dir = “/home/fengnazh/splittest/files/”
filterfile_list = os.listdir(filter_dir)
print filterfile_list
file_index = 0
while(file_index < len(filterfile_list)): print file_index tmpf = filter_dir + filterfile_list[file_index] print “000tmpf:” print tmpf if os.path.isfile(tmpf): print “go to if” root, ext = os.path.splitext(filterfile_list[file_index]) print root print ext if ext == ‘.old’: print “before file_index is %s ” % (file_index) print (filterfile_list[file_index]) filterfile_list.remove(filterfile_list[file_index]) #os.remove(os.path.join(tmpf)) file_index = file_index – 1 print “after file_index is %s ” % (file_index) print (filterfile_list[file_index]) print filterfile_list file_index = file_index + 1
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/139557.html原文链接:https://javaforall.cn
相关文章
- python进入文件目录 命令_python创建目录
- 一文搞定Python读取文件的全部知识
- Python-基础06-文件操作
- 用python画圣诞树、樱花树、卡通图案及打包成exe文件[通俗易懂]
- python写入txt文件中文乱码_python中怎么输入文件
- 推荐!国内气象人开发的基于Python的Grads文件解析利器
- 2022年最新Python大数据之Python基础【八】文件的操作与类
- Python 打开文件对话框「建议收藏」
- 为什么python读取不了文件_python系统找不到指定文件怎么办
- python处理xps文件_xps/pdf/png/json转换
- crontab 用法(执行python文件)[通俗易懂]
- python 快速读取压缩包内文件
- Python 调用接口进行文件上传的踩坑记录
- python怎么读取xlsx文件_arcgis地理加权回归
- python将py文件编译成exe文件_怎么把python程序打包成可执行文件