4#include "../Common/CompilerMacrosExport.h"
5#ifndef SC_EXPORT_LIBRARY_FILE_SYSTEM_ITERATOR
6#define SC_EXPORT_LIBRARY_FILE_SYSTEM_ITERATOR 0
8#define SC_FILE_SYSTEM_ITERATOR_EXPORT SC_COMPILER_LIBRARY_EXPORT(SC_EXPORT_LIBRARY_FILE_SYSTEM_ITERATOR)
10#include "../Common/Assert.h"
11#include "../Common/IGrowableBufferStringPath.h"
12#include "../Common/Result.h"
16SC_DECLARE_ASSERT_PROVIDER(FileSystemIteratorAssert, SC_FILE_SYSTEM_ITERATOR_EXPORT);
18#define SC_FILE_SYSTEM_ITERATOR_ASSERT_RELEASE(e) SC_ASSERT_PROVIDER_RELEASE(SC::FileSystemIteratorAssert, e)
19#define SC_FILE_SYSTEM_ITERATOR_ASSERT_DEBUG(e) SC_ASSERT_PROVIDER_DEBUG(SC::FileSystemIteratorAssert, e)
20#define SC_FILE_SYSTEM_ITERATOR_TRUST_RESULT(expression) SC_FILE_SYSTEM_ITERATOR_ASSERT_RELEASE(expression)
57#if SC_PLATFORM_WINDOWS
58 void* fileDescriptor = (
void*)(
long long)-1;
60 int fileDescriptor = -1;
61 void* dirEnumerator =
nullptr;
63 size_t textLengthInBytes = 0;
79#if SC_PLATFORM_WINDOWS
80 void* parentFileDescriptor =
nullptr;
82 int parentFileDescriptor = 0;
106 errorsChecked =
true;
114 Result
init(StringSpan directory, Span<FolderState> recursiveEntries);
127 static constexpr auto MaxPath = StringPath::MaxPath;
131 Span<FolderState> recursiveEntries;
133 int currentEntry = -1;
139 size_t size()
const {
return size_t(currentEntry + 1); }
140 bool isEmpty()
const {
return currentEntry == -1; }
142 RecurseStack recurseStack;
145 Result errorResult = Result(
true);
146 bool errorsChecked =
false;
148#if SC_PLATFORM_WINDOWS
149 bool expectDotDirectories =
true;
150 StringPath currentPath;
151 StringPath outputPath;
152 uint64_t dirEnumeratorBuffer[592 /
sizeof(uint64_t)];
154 StringPath currentPath;
157 Result enumerateNextInternal(Entry& entry);
158 Result recurseSubdirectoryInternal(Entry& entry);
Contains information on a file or directory.
Definition FileSystemIterator.h:70
bool isDirectory() const
Check if current entry is a directory.
Definition FileSystemIterator.h:77
uint32_t level
Current level of nesting from start of iteration.
Definition FileSystemIterator.h:73
StringSpan path
Absolute path of the current entry.
Definition FileSystemIterator.h:72
StringSpan name
Name of current entry (file with extension or directory)
Definition FileSystemIterator.h:71
Type type
Tells if it's a file or a directory.
Definition FileSystemIterator.h:74
Holds state of a folder when recursing into it to list its files.
Definition FileSystemIterator.h:56
Options when iterating (recursive and other options)
Definition FileSystemIterator.h:88
bool forwardSlashes
true will return paths forward slash / even on Windows
Definition FileSystemIterator.h:90
bool recursive
true will recurse automatically into subdirectories
Definition FileSystemIterator.h:89
Iterates files and directories inside a given path without allocating any memory.
Definition FileSystemIterator.h:46
const Entry & get() const
Get current Entry being iterated.
Definition FileSystemIterator.h:100
Result init(StringSpan directory, Span< FolderState > recursiveEntries)
Initializes the iterator on a given directory.
Options options
Options to control recursive behaviour and other options.
Definition FileSystemIterator.h:93
Result checkErrors()
Check if any error happened during iteration.
Definition FileSystemIterator.h:104
Result recurseSubdirectory()
Recurse into current item (assuming Entry::isDirectory == true)
Result enumerateNext()
Returned string is only valid until next enumerateNext call and/or another init call.
~FileSystemIterator()
Destroys the FileSystemIterator object.
Type
Entry type (File or Directory)
Definition FileSystemIterator.h:49