سؤال

I am trying to list all HTML files in a directory using os.walk but it returning none instead of file names

Here is my code

def read_dirctory():
    matches = []
    for root, dirnames, filenames in os.walk('/home/akallararajappan/www.mangalam.com/agriculture'):
        for filename in fnmatch.filter(filenames, '*.html'):
            matches.append(os.path.join(root, filename))
   return matches

What is the problem here ? I am using Ubuntu 12.04. I have 1000 html files in the directory

output:

[] 
هل كانت مفيدة؟

المحلول

Something like this should work. BTW there are a already a couple of questions like this.

def read_directory():
    matches =[]
    directory = '/home/akallararajappan/www.mangalam.com/agriculture'
    for root, dirs, files in os.walk(directory):
        for file in files:
            if file.endswith('.html'):
                matches.append(os.path.join(root, file))
    return matches
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top