Bird
0
0

You want to load all '.txt' and '.md' files from 'content' folder using DirectoryLoader. How can you do this?

hard📝 Application Q8 of 15
LangChain - Document Loading
You want to load all '.txt' and '.md' files from 'content' folder using DirectoryLoader. How can you do this?
ASet glob='*.txt,*.md' in one DirectoryLoader
BUse two DirectoryLoader instances, one for '*.txt' and one for '*.md', then combine results
CUse glob='*.(txt|md)' in DirectoryLoader
DDirectoryLoader cannot load multiple extensions at once
Step-by-Step Solution
Solution:
  1. Step 1: Understand glob limitations

    DirectoryLoader's glob does not support multiple patterns separated by commas or regex groups.
  2. Step 2: Use multiple loaders and combine

    Create two loaders with '*.txt' and '*.md' separately, then merge their loaded documents.
  3. Final Answer:

    Use two DirectoryLoader instances, one for '*.txt' and one for '*.md', then combine results -> Option B
  4. Quick Check:

    Multiple extensions need multiple loaders [OK]
Quick Trick: Use separate loaders for each file type, then merge [OK]
Common Mistakes:
  • Trying comma-separated glob
  • Using regex in glob
  • Assuming single loader handles multiple extensions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LangChain Quizzes