cxong/tinydir logo

cxong/tinydir

Free

Lightweight, portable and easy to integrate C directory and file reader

FreeFree tier
Type
Open Source

About cxong/tinydir

TinyDir is a lightweight, portable, and easy-to-integrate C directory and file reader implemented as a single header file (tinydir.h). It wraps the POSIX dirent API on Unix-like systems and the Windows FindFirstFile API on Windows, providing a consistent interface across platforms. Written in ANSI C (C90), it supports both POSIX and Windows, with optional Unicode support on Windows by defining UNICODE and _UNICODE. The library is open source under a Simplified BSD license, making it suitable for embedding in other projects. Known limitations include restricted path and filename sizes, a potential race condition when the directory contents change during iteration, and a 260-character maximum path length on Windows (no extended-length path support).

Key Features

Single header file implementation (tinydir.h) for easy integration
Cross-platform: wraps POSIX dirent and Windows FindFirstFile
ANSI C (C90) compatible
Optional Windows Unicode support via UNICODE and _UNICODE defines
Supports iterative and sorted directory reading with two API styles
Simplified BSD license (permissive, copy-left friendly)

Pros & Cons

Pros
  • Extremely lightweight and simple to integrate (single file)
  • Portable across POSIX and Windows with minimal changes
  • Permissive BSD license allows use in proprietary projects
  • Clear API with two usage styles (iterative and sorted) for flexibility
  • Active maintenance (latest release Dec 2023, 870 stars)
Cons
  • Limited to 260-character paths on Windows (no extended-length support)
  • Potential race condition if directory contents change during iteration
  • No support for reading file metadata beyond name and is_dir flag
  • Only one header file, so no separate compilation or namespace control

Best For

Listing directory contents in cross-platform C applicationsBuilding file browsers or command-line directory navigatorsEmbedded systems requiring a minimal filesystem abstractionPorting legacy C code that relies on platform-specific directory APIsEducational tool for learning directory traversal in C

FAQ

What platforms does tinydir support?
POSIX (Linux, macOS, etc.) via dirent and Windows via FindFirstFile. The library may be extended to other platforms.
What license does tinydir use?
Simplified BSD license. Users can comply by including tinydir.h or the COPYING file in their package.
Does tinydir support Unicode file names?
Windows Unicode support is available by defining UNICODE and _UNICODE before including tinydir.h.
What are the known limitations of tinydir?
Limited path and filename sizes, possible race condition if the folder content changes while reading, and no support for extended-length paths (over 260 characters) on Windows.