Implementation:Infiniflow Ragflow File Utils
| Knowledge Sources | |
|---|---|
| Domains | Infrastructure, File_System |
| Last Updated | 2026-02-12 06:00 GMT |
Overview
Concrete tool for resolving the project root directory and traversing file trees provided by the RAGFlow common library.
Description
The file_utils module provides get_project_base_directory to resolve the project root using RAG_PROJECT_BASE or RAG_DEPLOY_BASE environment variables, and traversal_files to recursively yield all file paths from a base directory.
Usage
Import get_project_base_directory when constructing file paths relative to the project root. Import traversal_files when scanning directory trees for document processing or configuration discovery.
Code Reference
Source Location
- Repository: Infiniflow_Ragflow
- File: common/file_utils.py
- Lines: 1-40
Signature
def get_project_base_directory(*args) -> str:
"""Resolve project root directory from environment or filesystem."""
def traversal_files(base: str):
"""Generator yielding all file paths recursively from base directory."""
Import
from common.file_utils import get_project_base_directory, traversal_files
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| args | str | No | Additional path components to join |
| base | str | Yes | Root directory for file traversal |
Outputs
| Name | Type | Description |
|---|---|---|
| get_project_base_directory() returns | str | Absolute path to project root |
| traversal_files() returns | Generator[str] | File paths found recursively |
Usage Examples
from common.file_utils import get_project_base_directory, traversal_files
# Get project root
root = get_project_base_directory()
# Get path to config
conf_path = get_project_base_directory("conf", "service_conf.yaml")
# Scan all files
for filepath in traversal_files("/data/documents"):
print(filepath)