BrowseFiles Manual

About

The BrowseFiles class provides means to iterate through the content of a directory.

Using the BrowseFiles class always follows the same concept:

Note
For browsing files with the MAXON API see Url Manual.
// This example demonstrates browsing a directory's content with BrowseFiles.
// Let user select an arbitrary directory to browse.
if (!folderName.FileSelect(FILESELECTTYPE::ANYTHING, FILESELECT::DIRECTORY, "Select a directory..."_s))
return maxon::OK;
// Allocate a BrowseFiles instance.
if (bf == nullptr)
return maxon::OutOfMemoryError(MAXON_SOURCE_LOCATION);
// Initialize the BrowseFiles instance.
const Int32 bfFlags = BROWSEFILES_CALCSIZE;
bf->Init(folderName, bfFlags);
// Print the directory content.
ApplicationOutput("Content of @", maxon::String(folderName.GetString()));
while (bf->GetNext()) // Note: GetNext() needs to be called at least once, to get the first element.
{
maxon::String sIsBundle = "_"_s, sIsHidden = "_"_s, sIsReadOnly = "_"_s, sIsDir = "_"_s;
maxon::String sSize = "dir"_s;
LocalFileTime timeCreated;
maxon::String sTimeCreated;
// Gather file information flags.
if (bf->IsBundle())
sIsBundle = "b"_s;
if (bf->IsHidden())
sIsHidden = "h"_s;
if (bf->IsReadOnly())
sIsReadOnly = "r"_s;
if (bf->IsDir())
sIsDir = "d"_s;
else
sSize = maxon::String::MemorySizeToString(bf->GetSize()); // GetSize() is only valid for files.
// Get creation time and convert it into a string.
bf->GetFileTime(GE_FILETIME_CREATED, &timeCreated); // other options: GE_FILETIME_MODIFIED and GE_FILETIME_ACCESS
sTimeCreated = maxon::String::IntToString(timeCreated.year);
sTimeCreated += "-"_s + maxon::String::IntToString(timeCreated.month);
sTimeCreated += "-"_s + maxon::String::IntToString(timeCreated.day);
sTimeCreated += " "_s + maxon::String::IntToString(timeCreated.hour);
sTimeCreated += ":"_s + maxon::String::IntToString(timeCreated.minute);
sTimeCreated += ":"_s + maxon::String::IntToString(timeCreated.second);
// Call a small custom function to get a string with decoded file attributes, see File Functions Manual.
FileGetAttributesString(folderName + bf->GetFilename(), sAttr) iferr_return; // Note: Pass complete path to file here!
// Finally print all information in one line.
ApplicationOutput("[@ @ @ @] - @ - @ - @ - @"_s, sIsDir, sIsBundle, sIsHidden, sIsReadOnly, sSize, sTimeCreated, sAttr, fileName);
}

Allocation/Deallocation

BrowseFiles objects are created with the usual tools, see Entity Creation and Destruction Manual (Classic).

Use

Browse

Note
BrowseFiles::GetNext() needs to be called at least once, in order to get the first element and for the following "File Info" functions to work.

File Info

Further Reading

FILESELECT::DIRECTORY
@ DIRECTORY
Folder selection dialog.
LocalFileTime::hour
UInt16 hour
Actual hour. (Between 0 and 23. 4 pm = 16.)
Definition: c4d_file.h:779
BrowseFiles::GetFilename
Filename GetFilename(void)
BrowseFiles::IsHidden
Bool IsHidden(void)
BrowseFiles::GetFileTime
void GetFileTime(Int32 mode, LocalFileTime *out)
LocalFileTime::minute
UInt16 minute
Actual minute. (Between 0 and 59.)
Definition: c4d_file.h:780
GE_FILETIME_CREATED
#define GE_FILETIME_CREATED
File time created.
Definition: c4d_file.h:892
maxon::String
Definition: string.h:1213
BROWSEFILES_CALCSIZE
#define BROWSEFILES_CALCSIZE
Specifies if BrowseFiles::GetSize() can be called later on. Only works for files, not for folders.
Definition: c4d_file.h:900
maxon::OK
return OK
Definition: apibase.h:2546
LocalFileTime::month
UInt16 month
Month. (Actual month, e.g. September = 9.)
Definition: c4d_file.h:777
FILESELECTTYPE::ANYTHING
@ ANYTHING
Any file.
iferr_return
#define iferr_return
Definition: resultbase.h:1465
MAXON_SOURCE_LOCATION
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:66
BrowseFiles::IsDir
Bool IsDir(void)
LocalFileTime::year
UInt16 year
Year. (Actual year, e.g. 2005 A.D. = 2005.)
Definition: c4d_file.h:776
LocalFileTime::second
UInt16 second
Actual second. (Between 0 and 59.)
Definition: c4d_file.h:781
BrowseFiles::GetSize
Int64 GetSize(void)
Filename::GetFileString
String GetFileString(void) const
BrowseFiles::IsBundle
Bool IsBundle(void)
BrowseFiles::Init
void Init(const Filename &directory, Int32 flags)
LocalFileTime::day
UInt16 day
Day. (Actual day, e.g. 30 = 30.)
Definition: c4d_file.h:778
Int32
maxon::Int32 Int32
Definition: ge_sys_math.h:60
ApplicationOutput
#define ApplicationOutput(formatString,...)
Definition: debugdiagnostics.h:208
AutoAlloc
Definition: ge_autoptr.h:36
BrowseFiles::IsReadOnly
Bool IsReadOnly(void)
BrowseFiles::GetNext
Bool GetNext(void)
LocalFileTime
Represents a date time.
Definition: c4d_file.h:773