python loop through files in directory recursively 1

python loop through files in directory recursively

import os
rootdir = './path/to/files/'

for subdir, dirs, files in os.walk(rootdir):
    for file in files:
        print os.path.join(subdir, file)

Here is what the above code is Doing:
1. We’re using os.walk to iterate through all the files in the root directory.
2. We’re printing the path to each file.

Similar Posts