Wednesday, February 3, 2016

Good and Pythonic way to iterate over files in a folder



First, we get the path by some way, most of cases with an open folder dialog.

Then we make a list with all files in that folder.

This can be useful for batch analyze / read/ write files.


import os


path = 'c://temp'
onlyfiles = [ f for f in os.listdir(path) if os.path.isfile(os.path.join(path,f))]

No comments:

Post a Comment