# Bulk Upload

Learn how to efficiently process multiple files with Fractur AI

Here’s how to efficiently process multiple files using Fractur AI’s async capabilities.

### [​](https://docs.chunkr.ai/docs/use-cases/bulk-upload#process-a-directory)Process a Directory <a href="#process-a-directory" id="process-a-directory"></a>

Here’s a simple script to process all files in a directory:

Python

```python
import asyncio
from chunkr_ai import Chunkr
import os
from pathlib import Path

chunkr = Chunkr()

async def process_directory(input_dir: str, output_dir: str):
    try:
        # Create output directory if it doesn't exist
        os.makedirs(output_dir, exist_ok=True)
        
        # Get all files in directory
        files = list(Path(input_dir).glob('*.*'))
        print(f"Found {len(files)} files to process")
        
        # Process files concurrently
        tasks = []
        for file_path in files:
            task = asyncio.create_task(process_file(chunkr, file_path, output_dir))
            tasks.append(task)
        
        # Wait for all files to complete
        results = await asyncio.gather(*tasks)
        
        print(f"Completed processing {len(results)} files")
    except Exception as e:
        print(f"Error processing directory: {e}")

async def process_file(chunkr, file_path, output_dir):
    try:
        # Upload file
        result = await chunkr.upload(file_path)
        
        # Check if upload was successful
        if result.status == "Failed":
            print(f"Failed to process file {file_path}: {result.message}")
            return None
        
        # Save result
        file_name = file_path.name
        output_file_path = Path(output_dir) / f"{file_name}.json"
        result.json(output_file_path)
        
        return file_name
    except Exception as e:
        print(f"Error processing file {file_path}: {e}")
        return None


# Run the processor
if __name__ == "__main__":
    INPUT_DIR = "/data/Chunkr/dataset/files"
    OUTPUT_DIR = "processed/"
    asyncio.run(process_directory(INPUT_DIR, OUTPUT_DIR))
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://fractur.gitbook.io/fractur/use-cases/bulk-upload.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
