P
P
Philip Polikarenkov2015-10-25 14:00:26
Python
Philip Polikarenkov, 2015-10-25 14:00:26

Why doesn't os.path.isdir work?

import os
import glob

def finder(path,mask):
    os.chdir(path)
    print(os.getcwd())
    if len(glob.glob(mask)):
        print(glob.glob(mask))
    dir_list = os.listdir()    
    for dirt in dir_list:
        if os.path.isdir(os.path.abspath(dirt)):# строка 1
            print(dirt)
            finder(dirt,mask)
        else:
            print(dirt,'is not dir')

The code should receive the path and use it to search for files by pattern.
But for some reason, when checking, it turns out that most of the folders are not folders, what's the problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Z
zed, 2015-10-25
@Vilibb

Python - how to find files and skip directories in...

basepath = '/path/to/directory'
for fname in os.listdir(basepath):
    path = os.path.join(basepath, fname)
    if os.path.isdir(path):
        # skip directories
        continue

D
Dimonchik, 2015-10-25
@dimonchik2013

there is such a thing - code 766ebebaeb634c06875474d2a5f0b70a.JPG

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question