Python not recognising directories os.path.isdir()

Viewed 33237

I have the following Python code to remove files in a directory. For some reason my .svn directories are not being recognised as directories.

And I get the following output:

.svn not a dir

Any ideas would be appreciated.

def rmfiles(path, pattern):
    pattern = re.compile(pattern)
    for each in os.listdir(path):
        if os.path.isdir(each) != True:
            print(each +  " not a dir")
            if pattern.search(each):
                name = os.path.join(path, each)
                os.remove(name)
3 Answers
Related