Itzik984 Itzik984 - 1 year ago 92
Python Question

How can I iterate over files in a given directory?

I need to iterate through all

files of a given directory and do some actions on them.

How can this be done in a efficient way?

Answer Source
for filename in os.listdir(directory):
    if filename.endswith(".asm") or filename.endswith(".py"): 
        # print(os.path.join(directory, filename))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download