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.
const maxon::String fileName = maxon::String(bf->GetFilename().GetFileString());
ApplicationOutput("[@ @ @ @] - @ - @ - @ - @"_s, sIsDir, sIsBundle, sIsHidden, sIsReadOnly, sSize, sTimeCreated, sAttr, fileName);
}
Definition: ge_autoptr.h:37
Represents a date time.
Definition: c4d_file.h:789
UInt16 year
Year. (Actual year, e.g. 2005 A.D. = 2005.)
Definition: c4d_file.h:791
UInt16 hour
Actual hour. (Between 0 and 23. 4 pm = 16.)
Definition: c4d_file.h:794
UInt16 minute
Actual minute. (Between 0 and 59.)
Definition: c4d_file.h:795
UInt16 second
Actual second. (Between 0 and 59.)
Definition: c4d_file.h:796
UInt16 month
Month. (Actual month, e.g. September = 9.)
Definition: c4d_file.h:792
UInt16 day
Day. (Actual day, e.g. 30 = 30.)
Definition: c4d_file.h:793
Definition: string.h:1235
maxon::Int32 Int32
Definition: ge_sys_math.h:60
#define BROWSEFILES_CALCSIZE
Specifies if BrowseFiles::GetSize() can be called later on. Only works for files, not for folders.
Definition: c4d_file.h:915
return OK
Definition: apibase.h:2690
@ DIRECTORY
Folder selection dialog.
@ ANYTHING
Any file.
#define GE_FILETIME_CREATED
File time created.
Definition: c4d_file.h:907
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:67
#define ApplicationOutput(formatString,...)
Definition: debugdiagnostics.h:210
#define iferr_return
Definition: resultbase.h:1519

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