BrowseFiles Manual
The BrowseFiles class provides means to iterate through the content of a directory.
使用 BrowseFiles class always follows the same concept:
// 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()));
// 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); }
BrowseFiles objects are created with the usual tools, see Entity Creation and Destruction Manual (Classic) .