BrowseFiles Manual

内容表

关于

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

使用 BrowseFiles class always follows the same concept:

注意
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. AutoAlloc<BrowseFiles> bf; 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; maxon::String sAttr;

// 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); }

Allocation/Deallocation

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

使用

浏览

注意
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

延伸阅读

FILESELECT::DIRECTORY
@ DIRECTORY
Folder selection dialog.
LocalFileTime::hour
UInt16 hour
Actual hour. (Between 0 and 23. 4 pm = 16.)
定义: 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.)
定义: c4d_file.h:780
GE_FILETIME_CREATED
#define GE_FILETIME_CREATED
File time created.
定义: c4d_file.h:892
maxon::String
定义: string.h:1197
BROWSEFILES_CALCSIZE
#define BROWSEFILES_CALCSIZE
Specifies if BrowseFiles::GetSize() can be called later on. Only works for files, not for folders.
定义: c4d_file.h:900
maxon::OK
return OK
定义: apibase.h:2532
LocalFileTime::month
UInt16 month
Month. (Actual month, e.g. September = 9.)
定义: c4d_file.h:777
FILESELECTTYPE::ANYTHING
@ ANYTHING
Any file.
iferr_return
#define iferr_return
定义: resultbase.h:1434
MAXON_SOURCE_LOCATION
#define MAXON_SOURCE_LOCATION
定义: memoryallocationbase.h:66
BrowseFiles::IsDir
Bool IsDir(void)
LocalFileTime::year
UInt16 year
Year. (Actual year, e.g. 2005 A.D. = 2005.)
定义: c4d_file.h:776
LocalFileTime::second
UInt16 second
Actual second. (Between 0 and 59.)
定义: 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.)
定义: c4d_file.h:778
Int32
maxon::Int32 Int32
定义: ge_sys_math.h:58
ApplicationOutput
#define ApplicationOutput(formatString,...)
定义: debugdiagnostics.h:207
AutoAlloc
定义: ge_autoptr.h:36
BrowseFiles::IsReadOnly
Bool IsReadOnly(void)
BrowseFiles::GetNext
Bool GetNext(void)
LocalFileTime
Represents a date time.
定义: c4d_file.h:773

Copyright  © 2014-2025 乐数软件    

工业和信息化部: 粤ICP备14079481号-1