4#include "../Foundation/Compiler.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 "../Foundation/Result.h"
11#include "../Foundation/StringPath.h"
51#if SC_PLATFORM_WINDOWS
52 void* fileDescriptor = (
void*)(
long long)-1;
54 int fileDescriptor = -1;
55 void* dirEnumerator =
nullptr;
57 size_t textLengthInBytes = 0;
73#if SC_PLATFORM_WINDOWS
74 void* parentFileDescriptor =
nullptr;
76 int parentFileDescriptor = 0;
94 const Entry&
get()
const {
return currentEntry; }
100 errorsChecked =
true;
127 int currentEntry = -1;
133 size_t size()
const {
return size_t(currentEntry + 1); }
134 bool isEmpty()
const {
return currentEntry == -1; }
136 RecurseStack recurseStack;
139 Result errorResult = Result(
true);
140 bool errorsChecked =
false;
142#if SC_PLATFORM_WINDOWS
143 bool expectDotDirectories =
true;
144 StringPath currentPath;
147 StringPath currentPath;
150 Result enumerateNextInternal(Entry& entry);
151 Result recurseSubdirectoryInternal(Entry& entry);
unsigned long size_t
Platform independent unsigned size type.
Definition PrimitiveTypes.h:56
unsigned long long uint64_t
Platform independent (8) bytes unsigned int.
Definition PrimitiveTypes.h:42
unsigned int uint32_t
Platform independent (4) bytes unsigned int.
Definition PrimitiveTypes.h:38
Contains information on a file or directory.
Definition FileSystemIterator.h:64
bool isDirectory() const
Check if current entry is a directory.
Definition FileSystemIterator.h:71
uint32_t level
Current level of nesting from start of iteration.
Definition FileSystemIterator.h:67
StringSpan path
Absolute path of the current entry.
Definition FileSystemIterator.h:66
StringSpan name
Name of current entry (file with extension or directory)
Definition FileSystemIterator.h:65
Type type
Tells if it's a file or a directory.
Definition FileSystemIterator.h:68
Holds state of a folder when recursing into it to list its files.
Definition FileSystemIterator.h:50
Options when iterating (recursive and other options)
Definition FileSystemIterator.h:82
bool forwardSlashes
true will return paths forward slash / even on Windows
Definition FileSystemIterator.h:84
bool recursive
true will recurse automatically into subdirectories
Definition FileSystemIterator.h:83
Iterates files and directories inside a given path without allocating any memory.
Definition FileSystemIterator.h:40
const Entry & get() const
Get current Entry being iterated.
Definition FileSystemIterator.h:94
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:87
Result checkErrors()
Check if any error happened during iteration.
Definition FileSystemIterator.h:98
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:43
An ascii string used as boolean result. SC_TRY macro forwards errors to caller.
Definition Result.h:13
View over a contiguous sequence of items (pointer + size in elements).
Definition Span.h:29
static constexpr size_t MaxPath
Maximum size of paths on current native platform.
Definition StringPath.h:49
An read-only view over a string (to avoid including Strings library when parsing is not needed).
Definition StringSpan.h:37