VCF::Directory Class Reference
A Directory represents a directory in a filesystem. More...
#include <vcf/FoundationKit/Directory.h>
Inheritance diagram for VCF::Directory:

Public Member Functions | |
| Directory (const String &fileName="") | |
| Directory (const FilePath &filePath) | |
| virtual | ~Directory () |
| virtual void | setName (const String &fileName) |
| sets the name of the Directory and creates the peer if it does not exists yet It makes sure the name is a well formed directory name i.e. | |
| Finder * | findFiles (const String &filterFile=L"", const String &filterDir=L"") |
| Creates, initializes and returns a Finder object to perform a directory/files search. | |
| Finder * | findFiles (FileSearchFilter *filterFileObject, const bool &ownFilterFileObject=false) |
| Creates, initializes and returns a Finder object to perform a directory/files search. | |
Classes | |
| class | Finder |
| A Finder object is used to iterate a set of files contained in a Directory object that represents the directory. More... | |
Detailed Description
A Directory represents a directory in a filesystem.and therefore it is a File object with all its features.
In addition they can instantiate a Directory::Finder object in the moment the user wants them to perform a search into its files and subdirectories based on a search filter.
The Directory::Finder class has been written to be very performant even when recursing.
The way to use this class is:
String filepath = L"./"; String filename; File* file = NULL; Directory dir( FilePath::getExpandedRelativePathName( filepath ) ); Directory::Finder* finder = dir.findFiles( "*.cpp" ); finder->setDisplayMode( Directory::Finder::dmFiles ); while ( finder->nextElement() ) { file = finder->getCurrentElement(); filename = file->getName(); if ( file->isDirectory() ) { printf ( "[%s]\n", filename.ansi_c_str() ) } else { printf ( "%s\n", filename.ansi_c_str() ) } } finder->free();
The user is also able to create more than one finder from the same directory instance. But in order to achieve that we made the user responsible of freeing the finder.
The statements:
finder->setMaskFilterFileAttribs( File::faArchive ); finder->ignoreStat( File::smMaskDateAll );
It is possible to easily recurse into subdirectories. The following code will let you to recurse up to 10 levels while applying a personalized filter. The filter can be as flexible as desired.
FilSearchFilterStandard filterFilesObj( L"*.h", L"src/vcf" ); String filepath = L"./"; String filename; File* file = NULL; Directory dir( FilePath::getExpandedRelativePathName( filepath ) ); Directory::Finder* finder = dir.findFiles( filterFilesObj, filterDirsObj ); finder->setDisplayMode( Directory::Finder::dmAny ); finder->setRecursion( true, 10 ); while ( finder->nextElement() ) { file = finder->getCurrentElement(); filename = file->getName(); if ( file->isDirectory() ) { String st = StringUtils::format( convertUtcToLocal( file->getDateModified() ), L"%d/%m/%Y %H:%M:%S" ); printf ( "[%d] %s %10s %5s [%s]\n", finder->getRecursionLevel(), st.ansi_c_str(), "", "", filename.ansi_c_str() ); } else { String sz = StringUtils::toString( file->getSize() ); String st = StringUtils::format( file->getDateModified(), L"%d/%m/%Y %H:%M:%S" ); String sa = StringUtils::format( "%c%c%c%c%c", file->isArchive()?'a':' ', file->isReadOnly()?'r':' ', file->isHidden()?'h':' ', file->isSystem()?'s':' ', file->isExecutable()?'x':' ' ); printf ( "[%d] %s %10s %s %s\n", finder->getRecursionLevel(), st.ansi_c_str(), sz.ansi_c_str(), sa.ansi_c_str(), filename.ansi_c_str() ); } } finder->free();
The statements:
finder->setDisplayMode( Directory::Finder::dmAny ); finder->setDisplayOrder( Directory::Finder::dmFiles );
Normally the filenames are displayed in the native format, but the statement:
finder->setKeepOSSpecificFormat( true );
Constructor & Destructor Documentation
|
|
|
|
|
|
|
|
|
Member Function Documentation
|
||||||||||||
|
Creates, initializes and returns a Finder object to perform a directory/files search.
|
|
||||||||||||
|
Creates, initializes and returns a Finder object to perform a directory/files search.
|
|
|
sets the name of the Directory and creates the peer if it does not exists yet It makes sure the name is a well formed directory name i.e. with the 'DirectorySeparator' at the end
Reimplemented from VCF::File. |
The documentation for this class was generated from the following file:
- vcf/FoundationKit/Directory.h
