https://github.com/cxong/tinydir
Lightweight, portable and easy to integrate C directory and file reader
https://github.com/cxong/tinydir
c directory filesystem header-only portable posix
Last synced: 9 days ago
JSON representation
Lightweight, portable and easy to integrate C directory and file reader
- Host: GitHub
- URL: https://github.com/cxong/tinydir
- Owner: cxong
- License: other
- Created: 2013-02-01T10:05:40.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2024-02-27T21:55:08.000Z (about 1 year ago)
- Last Synced: 2025-04-02T06:41:44.757Z (about 2 months ago)
- Topics: c, directory, filesystem, header-only, portable, posix
- Language: C
- Homepage:
- Size: 172 KB
- Stars: 828
- Watchers: 37
- Forks: 128
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: COPYING
- Security: SECURITY.md
Awesome Lists containing this project
- awesomecpp - TinyDir - - lightweight, portable and easy to integrate C directory and file reader. (File Managment)
- AwesomeCppGameDev - tinydir
README
TinyDir
=======
[](https://github.com/cxong/tinydir/actions/workflows/cmake.yml)
[](https://github.com/cxong/tinydir/releases/latest)Lightweight, portable and easy to integrate C directory and file reader. TinyDir wraps dirent for POSIX and FindFirstFile for Windows.
Windows unicode is supported by defining `UNICODE` and `_UNICODE` before including `tinydir.h`.
Example
=======There are two methods. Error checking omitted:
```C
tinydir_dir dir;
tinydir_open(&dir, "/path/to/dir");while (dir.has_next)
{
tinydir_file file;
tinydir_readfile(&dir, &file);printf("%s", file.name);
if (file.is_dir)
{
printf("/");
}
printf("\n");tinydir_next(&dir);
}tinydir_close(&dir);
``````C
tinydir_dir dir;
int i;
tinydir_open_sorted(&dir, "/path/to/dir");for (i = 0; i < dir.n_files; i++)
{
tinydir_file file;
tinydir_readfile_n(&dir, &file, i);printf("%s", file.name);
if (file.is_dir)
{
printf("/");
}
printf("\n");
}tinydir_close(&dir);
```See the `/samples` folder for more examples, including an interactive command-line directory navigator.
Language
========ANSI C, or C90.
Platforms
=========POSIX and Windows supported. Open to the possibility of supporting other platforms.
License
=======Simplified BSD; if you use tinydir you can comply by including `tinydir.h` or `COPYING` somewhere in your package.
Known Limitations
=================- Limited path and filename sizes
- [Possible race condition bug if folder being read has changing content](https://github.com/cxong/tinydir/issues/13)
- Does not support extended-length path lengths in Windows - paths are limited to 260 characters. See