Python 谁能解释一下为什么os.remove不';你不能正常工作吗?

Python 谁能解释一下为什么os.remove不';你不能正常工作吗?,python,python-3.x,Python,Python 3.x,在这些文件夹中有一个包含文件夹和图像的存储库。关键是我不知道这个方法os.remove是如何工作的。在某些文件夹中,它会删除不需要的文件,在某些文件夹中不会,也有一些文件夹的大小正在缩小(10-15个图像),有些则不会。我错过了什么 dirs = next(os.walk(path))[1] for d in dirs: dirPath = path + d os.chdir(dirPath) dirPath = path + d files = ne

在这些文件夹中有一个包含文件夹和图像的存储库。关键是我不知道这个方法os.remove是如何工作的。在某些文件夹中,它会删除不需要的文件,在某些文件夹中不会,也有一些文件夹的大小正在缩小(10-15个图像),有些则不会。我错过了什么

dirs = next(os.walk(path))[1]

for d in dirs:
    dirPath = path  + d
    os.chdir(dirPath)

    dirPath = path  + d


    files = next(os.walk(dirPath))[2]

    for f in files:
        if f is 'feature.bin': os.remove('feature.bin')      
        if f is 'filelist_LBP.txt': os.remove('filelist_LBP.txt')
        if f is 'info.txt': os.remove('info.txt')  

os.remove
需要删除文件的完整路径,除非它恰好位于当前目录中。

是否检查了dirs变量是否设置为某个值?因为如果它是子目录(即,它下面没有目录),您也不会遍历任何文件,当您的意思是“==”时,请避免使用“is”进行比较。有关更多详细信息,请参阅。