0

I'm using glob in Python 3.6 and trying to sequence match instead of using for loops:

glob("./*/*/*.(txt|json)")
glob("./*/(subdir1|subdir2)/*")

I was told this should work but it doesn't. Is this an issue with my syntax or is this functionality not supported?

kaega
  • 75
  • 6
  • What are you trying to match, and how doesn't it work? – thuyein Jun 06 '20 at 01:05
  • Just multiple filetypes at the same time. I could loop through a list like ['txt', 'json'] and glob a filepath with it but I wanted to see if this syntax worked – kaega Jun 06 '20 at 01:07
  • In short: not possible with glob. You'll need to do multiple calls. In one folder os.listdir + regexp matching on the result can work (though you want to span multiple folders according to your question so probably won't be good for you). – Alexander Pivovarov Jun 06 '20 at 01:11
  • Yes it does help. Awesome thanks for the answer! – kaega Jun 06 '20 at 01:13

0 Answers0