ON_FileIterator Class Reference

Iterates through every item in a file system directory. More...

#include <opennurbs_file_utilities.h>

Public Member Functions

 ON_FileIterator ()=default
 
 ~ON_FileIterator ()
 
ON__UINT64 CurrentItemCount () const
 
const ON_wString CurrentItemFullPathName () const
 
bool CurrentItemIsDirectory () const
 
bool CurrentItemIsFile () const
 
bool CurrentItemIsHidden () const
 
ON__UINT64 CurrentItemLastModifiedTime () const
 
const ON_wString CurrentItemName () const
 
ON__UINT64 CurrentItemSize () const
 
const ON_wString DirectoryName () const
 
bool FirstItem ()
 Find the first matching item in the directory. More...
 
bool Initialize (const wchar_t *directory_name)
 Initialize where the search should occur. More...
 
bool Initialize (const wchar_t *directory_name, const wchar_t *item_name_filter)
 
bool Initialize (const char *directory_name)
 
bool Initialize (const char *directory_name, const char *item_name_filter)
 
bool NextItem ()
 Find the next matching item in the directory. More...
 
void Reset ()
 Reset this ON_FileIterator so it can be used again. More...
 

Detailed Description

Iterates through every item in a file system directory.

Constructor & Destructor Documentation

◆ ON_FileIterator()

ON_FileIterator::ON_FileIterator ( )
default

◆ ~ON_FileIterator()

ON_FileIterator::~ON_FileIterator ( )

Member Function Documentation

◆ CurrentItemCount()

ON__UINT64 ON_FileIterator::CurrentItemCount ( ) const
Returns
Number of matching items iterated through.

◆ CurrentItemFullPathName()

const ON_wString ON_FileIterator::CurrentItemFullPathName ( ) const

◆ CurrentItemIsDirectory()

bool ON_FileIterator::CurrentItemIsDirectory ( ) const

◆ CurrentItemIsFile()

bool ON_FileIterator::CurrentItemIsFile ( ) const

◆ CurrentItemIsHidden()

bool ON_FileIterator::CurrentItemIsHidden ( ) const

◆ CurrentItemLastModifiedTime()

ON__UINT64 ON_FileIterator::CurrentItemLastModifiedTime ( ) const
Returns
File last modified time in seconds since January 1, 1970

The times returned by ON_FileIterator can differ from the time returned by ON_FileStream::GetFileInformation().

◆ CurrentItemName()

const ON_wString ON_FileIterator::CurrentItemName ( ) const
Returns
Current file or directory name in the directory being iterated. Use CurrentFullPathItemName() to get the full path name.

◆ CurrentItemSize()

ON__UINT64 ON_FileIterator::CurrentItemSize ( ) const
Returns
If the current item is a file, then the size of the file in bytes is returned. If the current item is a directory, then 0 is returned.

◆ DirectoryName()

const ON_wString ON_FileIterator::DirectoryName ( ) const
Returns
The name of the directory being iterated.

◆ FirstItem()

bool ON_FileIterator::FirstItem ( )

Find the first matching item in the directory.

Returns
true: The iterator is set to the first item. false: There are no matching items.
// Iterate through the files in a directory named "\rootdir\subdir"
fit.Initialize("\\rootdir\\subdir");
for ( bool bHaveItem = fit.FirstItem(); bHaveItem; bHaveItem = fit.NextItem() )
{
if ( fit.CurrentFileIsDirectory() )
continue;
FILE* fp = ON_FileStream::Open(fullpath,"rb");
if ( 0 == fp )
{
continue;
}
...
fp = 0;
}
}

◆ Initialize() [1/4]

bool ON_FileIterator::Initialize ( const wchar_t *  directory_name)

Initialize where the search should occur.

Parameters
directory_name[in] The directory to look in.
item_name_filter[in] If this paramter is null, then the iteration includes all names in the directory. The item name to search for. This parameter can include wildcard characters, such as an asterisk (*) or a question mark (?). For example, "\rootdir\subdir\*.*" will iterate all files in the \ directory.
Returns

true: The iterator is set to the first item. false: There are no matching items.

Calling FirstItem() is eqivalent to calling Initialize() and then calling NextItem().

◆ Initialize() [2/4]

bool ON_FileIterator::Initialize ( const wchar_t *  directory_name,
const wchar_t *  item_name_filter 
)

◆ Initialize() [3/4]

bool ON_FileIterator::Initialize ( const char *  directory_name)

◆ Initialize() [4/4]

bool ON_FileIterator::Initialize ( const char *  directory_name,
const char *  item_name_filter 
)

◆ NextItem()

bool ON_FileIterator::NextItem ( )

Find the next matching item in the directory.

Returns
true: The iterator was advanced to the next item. false: There are no more matching items.

◆ Reset()

void ON_FileIterator::Reset ( )

Reset this ON_FileIterator so it can be used again.