I want to loop through directory and process the files in them.
I do this with the following code.
for (root, subdirectories, files) in os.walk(dirDialoog.GetPath()):
for file in files:

My problem is that the files processed 2 times.
I tried the next code, but in that way the files weren't selected because the subdirectory is empty.
for (root, subdirectories, files) in os.walk(dirDialoog.GetPath()):
for subdirectoryNaam in subdirectories:

Anyone a suggestion how to solve my problem?

You might want to use os.listdir(directory) ...

# list filenames in a given directory

import os

# assign a directory name for test
directory = "C:/Python27/Atest27/Bull"

# os.listdir(directory) creates a list of filenames in directory 
#print(os.listdir(directory))  # test

# test print the list one filename each line
for fname in os.listdir(directory):
    print(fname)

''' example output >>
file_lines101.py
file_list101.py
file_with_statement1.py
file_with_statement2.py
find_concat_words101.py
find_multiple_words101.py
firstmod.py
firstmod.pyc
hello.py
hello.pyc
'''
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.