I'm using os.walk to run through directory "foo". I want to process .dat files but how to check for a directory name and only process the specific directory?
If dir="bar" then process files.dat. Do not process "notbar". I'm probably missing something simple
C:\data\foo
- notbar
-123
-file1.dat
-456
-file2.dat
-file3.dat
- bar
-123
-file1.dat
-456
-file2.dat
-file3.dat
this finds all .dat files....
for (root, dirnames, filenames) in os.walk(base_path):
print('Found directory: {0}'.format(root))
for filename in filenames:
if filename.endswith(".dat"):
print(filename)