README.md
1TinyDir
2=======
3[](https://github.com/cxong/tinydir/actions/workflows/cmake.yml)
4[](https://github.com/cxong/tinydir/releases/latest)
5
6Lightweight, portable and easy to integrate C directory and file reader. TinyDir wraps dirent for POSIX and FindFirstFile for Windows.
7
8Windows unicode is supported by defining `UNICODE` and `_UNICODE` before including `tinydir.h`.
9
10Example
11=======
12
13There are two methods. Error checking omitted:
14
15```C
16tinydir_dir dir;
17tinydir_open(&dir, "/path/to/dir");
18
19while (dir.has_next)
20{
21 tinydir_file file;
22 tinydir_readfile(&dir, &file);
23
24 printf("%s", file.name);
25 if (file.is_dir)
26 {
27 printf("/");
28 }
29 printf("\n");
30
31 tinydir_next(&dir);
32}
33
34tinydir_close(&dir);
35```
36
37```C
38tinydir_dir dir;
39int i;
40tinydir_open_sorted(&dir, "/path/to/dir");
41
42for (i = 0; i < dir.n_files; i++)
43{
44 tinydir_file file;
45 tinydir_readfile_n(&dir, &file, i);
46
47 printf("%s", file.name);
48 if (file.is_dir)
49 {
50 printf("/");
51 }
52 printf("\n");
53}
54
55tinydir_close(&dir);
56```
57
58See the `/samples` folder for more examples, including an interactive command-line directory navigator.
59
60Language
61========
62
63ANSI C, or C90.
64
65Platforms
66=========
67
68POSIX and Windows supported. Open to the possibility of supporting other platforms.
69
70License
71=======
72
73Simplified BSD; if you use tinydir you can comply by including `tinydir.h` or `COPYING` somewhere in your package.
74
75Known Limitations
76=================
77
78- Limited path and filename sizes
79- [Possible race condition bug if folder being read has changing content](https://github.com/cxong/tinydir/issues/13)
80- Does not support extended-length path lengths in Windows - paths are limited to 260 characters. See <https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=registry>
81