zl程序教程

您现在的位置是:首页 >  后端

当前栏目

python 去掉文件后缀名,python 删除后缀名文件

Python文件 删除 去掉 后缀名
2023-06-13 09:11:24 时间

大家好,又见面了,我是你们的朋友全栈君。

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