Metadata-Version: 2.4
Name: dirclass
Version: 0.1.0
Summary: Treat a directory like a dataclass for recursive file listing and reading.
Author-email: Rongxin Ouyang <rongxin@u.nus.edu>
License-Expression: MIT
Keywords: files,directories,dataclass,recursion,utilities
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Operating System :: OS Independent
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

<!--
 * @Date: 2025-08-14 15:41:37
 * @LastEditors: Rongxin rongxin@u.nus.edu
 * @LastEditTime: 2025-08-14 15:43:53
 * @FilePath: /dirclass/README.md
-->
## dirclass

Treat a directory like a dataclass for ease, recursively.

### Main features
- **Simple factory**: `dirclass(path, recursive=True, file_types="*") -> dataclass`
- **List files**: `d.all()` returns a flattened list of file paths
- **Read files**: `d.read_all()` returns a flattened list of file contents
- **Filtering**: Accept glob patterns like `"*.py"` or `["*.py", "*.md"]` in constructor or per-call
- **Subfolder properties**: Immediate subfolders become attributes (e.g., `.src`, `.data`)
  - Aliases: full sanitized name, tail after last dot (e.g., `path.src` → `.path_src` and `.src`), and case-insensitive access (e.g., `.Gallery` and `.gallery`)
- **Robust reading**: Read errors are logged and skipped (continues processing)

### Install (PyPI)
```bash
pip install dirclass
```
Alternatively, 

```bash
pip install -e .
```

### Usage
```python
from dirclass import dirclass

# Create a directory wrapper
d = dirclass("/path/to/folder", recursive=True, file_types=["*.py", "*.md"])

# List all matching files
paths = d.all()                 # list[str]

# Read contents of all matching files
contents = d.read_all()         # list[str]

# Override filters per call
py_only = d.all("*.py")
md_and_txt_contents = d.read_all(["*.md", "*.txt"])

# Subfolder properties (immediate children of the root)
# If your root has folders: src, data, and Gallery
src_files = d.src               # files under /path/to/folder/src
data_files = d.data             # files under /path/to/folder/data
gallery_files = d.Gallery       # case-insensitive access also works: d.gallery

# Dotted folder names (e.g., `path.src`) expose multiple aliases
# - full sanitized name: d.path_src
# - tail alias: d.src
```

### Example
```python
from dirclass import dirclass

d = dirclass("./project", recursive=True, file_types=["*.py", "*.md"]) 

print("All files:")
for p in d.all():
    print(p)

print("\nPython files only:")
for p in d.all("*.py"):
    print(p)

print("\nSubfolder: src")
for p in d.src:  # requires a ./project/src subfolder
    print(p)

print("\nReading markdown contents:")
for content in d.read_all("*.md"):
    print(content[:80], "...")
```

Codes are generated by GPT5, thus may not be reliable in the current version for test.
