0

I have a subfolder structure similar to this:

./job_1/hello/*.yml

./job_2/svk/.../*.yml

./job_3/kmd/.../*.yml

./job_4/sil/*.yml

./job_5/svk/.../*.yml

I only want to read from the .yml files under the jobs with subfolders "svk" and "kmd." Is there a way to do this in Python 2.7?

yeepo
  • 90
  • 6
  • 1
    Please repeat [on topic](https://stackoverflow.com/help/on-topic) and [how to ask](https://stackoverflow.com/help/how-to-ask) from the [intro tour](https://stackoverflow.com/tour). “Show me how to solve this coding problem” is not a Stack Overflow issue. We expect you to make an honest attempt, and *then* ask a *specific* question about your algorithm or technique. Look up how to traverse directories in Python; it's the `os` package. Start with the `walk` method and filter your results. – Prune Sep 17 '20 at 21:23
  • I guess this would be helpful for you. https://stackoverflow.com/questions/10989005/do-i-understand-os-walk-right#:~:text=walk()%20will%20generate%20tuple,keep%20on%20traversing%20the%20subfolders.&text=Here's%20a%20short%20example%20of%20how%20os.&text=walk()%20returns%20three%20items,files%20found%20in%20those%20directories. – Yossi Levi Sep 17 '20 at 21:28
  • you cat try to use `glob.glob(pattern)` to get filenames from `svk` and later second `glob.glob(pattern)` to get filenames from `kmd` . OR use `os.listdir()` or `os.walk()` to get all files and filter them using own code or `fnmatch` (which is used in `glob.glob()`) or using regex. – furas Sep 17 '20 at 23:28
  • first try to write code and come back when you get error message. – furas Sep 17 '20 at 23:29

0 Answers0