VCOM:Enumerating folder contents

From Vectorworks Developer
Jump to: navigation, search

.SDK|SDK ..SDK:Types|SDK Types ..VCOM:VCOM (Vectorworks Component Object Model)|VCOM Basics ..VCOM:Class Reference|VCOM Class Reference

Enumerating Folder Contents

Having valid VCOM:VectorWorks:Filing:IFolderIdentifier (see VCOM:Working with File Identifiers) will allow you to use IFolderIdentifier::EnumerateContents function to enumerate that folder contents.

Create Folder Listener Class

Before enumerating you have to create a class that will receive the folder contents. This you do by creating class implementing IFolderContentListener interface. (see remarks of IFolderIdentifier::EnumerateContents)

class CMyFolderListener : public IFolderContentListener
    CMyFolderListener(int someData)
        fSomeData = someData;

    void  GetFiles(TXStringArray& outArrFiles)
        outArrFiles = farrFiles;

// IFolderContentListener
    virtual EFolderContentListenerResult VCOM_CALLTYPE	OnFolderContent(IFolderIdentifier* pFolderID)
        TXString   folderName;
        pFolderID->GetName( folderName );

        return eFolderContentListenerResult_Continue;

    virtual EFolderContentListenerResult VCOM_CALLTYPE	OnFileContent(IFileIdentifier* pFileID)
        TXString   fileName;
        pFileID->GetFileName( fileName);

        farrFiles.Append( fileName );

        return eFolderContentListenerResult_Continue;

    int             fSomeData;

    TXStringArray   farrFiles;

This class extends IFolderContentListener which makes it folder listener. It is responsible for handing folder contents through virtual functions 'OnFolderContent' and 'OnFileContent'.

Also it can store local data that is received by the constructor and retreived by public member function.


When you want to enumerate, you create an instance of your listener class and call IFolderIdentifier::EnumerateContents of the VCOM:VectorWorks:Filing:IFolderIdentifier instance representing the folder you want to enumerate:

IFolderIdentifierPtr  pFolderID( IID_FolderIdentifier );
if ( VCOM_SUCCEEDED( pFolderID->Set( kExternalsFolder, false, "MyFolder" ) ) ) {
    CMyFolderListener   myContentsListener( 32 );
    pFolderID->EnumerateContents( & myContentsListener, false );

    TXStringArray    arrFiles;
    myContentsListener.GetFiles( arrFiles );

    // ...

See Also

Personal tools

Advanced Search
See Also