运行此脚本删除文件时没有属性错误,但没有任何反应

时间:2016-04-16 17:13:55

标签: python-2.7

此代码不会打印任何属性错误,也不会打印任何内容。我试图通过打印找到错误,所以我可以告诉为什么它不会在我的目录中循环我的文件并删除它们。

import os
import glob

def Test():

    path = ('/home/Jack/Python.files/') # Shows the path for all python files
    directories = os.listdir(path) # Finds the directory name

    v = path + directories[0] + ('/*.py~') 
    a = path + directories[1] + ('/*.py~')
    z = path + directories[2] + ('/*.py~')
    w = path + directories[3] + ('/*.py~')
    s = path + directories[4] + ('/*.py~')
    x = path + directories[5] + ('/*.py~')
    # Cocatinates path, directories, and files that end in .py~ together

    numbers = (v, a, z, w, s, x) 
    # Puts the file variables in a tupple

    for i in numbers: 
        if i in path: 
        # Iterates over the tupple for each string file   

            os.remove(i)
            print os.remove(glob.glob(i))
            # Places that string in os.remove and deletes the file

Test()

0 个答案:

没有答案