PCL
pcl::File::Find Class Reference

Directory search operation. More...

#include <File.h>

Public Member Functions

 Find ()=default
 
 Find (const Find &)=delete
 
 Find (const String &path)
 
 ~Find ()
 
void Begin (const String &path)
 
void End ()
 
bool NextItem (FindFileInfo &info)
 
Findoperator= (const Find &)=delete
 
String SearchPath () const
 

Detailed Description

This class can be used as an iterator to find all files and subdirectories within a directory tree.

In the following example, the ProcessFiles function calls a functor object, specified as the processFile function argument, for each file found recursively in the specified dirPath directory. The functor's unique argument is the absolute file path of an existing file.

template <class F>
void ProcessFiles( const String& dirPath, F processFile )
{
StringList directories;
for ( File::Find f( dirPath + '/' + '*' ); f.NextItem( info ); )
if ( info.IsDirectory() )
{
if ( info.name != "." && info.name != ".." )
directories << info.name;
}
else if ( !info.attributes.IsFlagSet( FileAttribute::SymbolicLink ) )
{
processFile( File::FullPath( dirPath + '/' + info.name ) );
}
for ( const String& dir : directories )
ProcessFiles( dirPath + '/' + dir );
}
See also
FindFileInfo

Definition at line 458 of file File.h.

Constructor & Destructor Documentation

◆ Find() [1/3]

pcl::File::Find::Find ( )
default

Constructs an inactive File::Find object.

◆ Find() [2/3]

pcl::File::Find::Find ( const String path)
inline

Constructs a File::Find object and starts a new directory search operation for the specified path.

The specified path can include wildcards to define a pattern to search for a set of directory items.

Definition at line 474 of file File.h.

◆ ~Find()

pcl::File::Find::~Find ( )
inline

Destroys a File::Find object. If a directory search operation is currently active, it is finalized.

Definition at line 483 of file File.h.

◆ Find() [3/3]

pcl::File::Find::Find ( const Find )
delete

Copy constructor. This constructor is disabled because File::Find instances are unique.

Member Function Documentation

◆ Begin()

void pcl::File::Find::Begin ( const String path)

Starts a new directory search operation for the specified path.

The specified path can include wildcards to define a pattern to search for a set of directory items.

◆ End()

void pcl::File::Find::End ( )

Finalizes the current directory search operation, if there is one active.

◆ NextItem()

bool pcl::File::Find::NextItem ( FindFileInfo info)

Attempts to retrieve the next item in the current directory search operation.

Returns true if a new item has been retrieved. In such case the info structure receives the data corresponding to the retrieved item. Returns false if there are no more items available, signaling the end of the current directory search operation, or if a search operation has not been initiated by a previous call to Begin(). In such case the info structure is not modified.

◆ operator=()

Find& pcl::File::Find::operator= ( const Find )
delete

Copy assignment. This operator is disabled because File::Find instances are unique.

◆ SearchPath()

String pcl::File::Find::SearchPath ( ) const
inline

Returns the search path of the current directory search operation.

Definition at line 530 of file File.h.


The documentation for this class was generated from the following file:
pcl::FindFileInfo::attributes
FileAttributes attributes
Item attributes.
Definition: File.h:194
pcl::FindFileInfo::IsDirectory
bool IsDirectory() const
Definition: File.h:206
StringList
Dynamic list of Unicode (UTF-16) strings.
pcl::FindFileInfo
File information structure used by File::Find
Definition: File.h:191
pcl::Flags::IsFlagSet
constexpr bool IsFlagSet(enum_type e) const
Definition: Flags.h:244
pcl::File::FullPath
static String FullPath(const String &path)
pcl::FindFileInfo::name
String name
File or directory name, including the file name extension.
Definition: File.h:193