Sourceforge.net - The VCF's Project Host
   The VCF Website Home   |   Online Discussion Forums   |   Sourceforge.net Project Page   

VCF::Directory Class Reference

A Directory represents a directory in a filesystem. More...

#include <vcf/FoundationKit/Directory.h>

Inheritance diagram for VCF::Directory:

VCF::File VCF::Object List of all members.

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.
FinderfindFiles (const String &filterFile=L"", const String &filterDir=L"")
 Creates, initializes and returns a Finder object to perform a directory/files search.
FinderfindFiles (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 );
can be used to speed up the search.

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 );
can be used to control how the found files are displayed and their order.

Normally the filenames are displayed in the native format, but the statement:

  finder->setKeepOSSpecificFormat( true );
will let the user to mantain the format specific for the OS.


Constructor & Destructor Documentation

VCF::Directory::Directory const String fileName = ""  ) 
 

VCF::Directory::Directory const FilePath filePath  ) 
 

virtual VCF::Directory::~Directory  )  [virtual]
 


Member Function Documentation

Finder* VCF::Directory::findFiles FileSearchFilter filterFileObject,
const bool &  ownFilterFileObject = false
 

Creates, initializes and returns a Finder object to perform a directory/files search.

Parameters:
FileSearchFilter a filter object to filter the search for files and/or subdirectories. Use NULL to disable any filtering on files or subdirectories.
bool ownFilterFileObject true if you want the Finder to be responsible for its deletion Please use false when the filter object is allocated on the stack.
Exceptions:
BasicException if the filename is not a full path name.

Finder* VCF::Directory::findFiles const String filterFile = L"",
const String filterDir = L""
 

Creates, initializes and returns a Finder object to perform a directory/files search.

Parameters:
String a filter string for a simple filtering of the file names.
String a filter string for a simple filtering of the path names. These two strings are internally represented by an instance of FileSearchFilterStandard.
Exceptions:
BasicException if the filename is not a full path name.

void VCF::Directory::setName const String fileName  )  [inline, virtual]
 

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

Parameters:
fileName the name

Reimplemented from VCF::File.


The documentation for this class was generated from the following file:
   Comments or Suggestions?    License Information