class directory_files_iterator

Iterator over the files ( sfile ) immediately contained in a directory ( directory ).

Initialize with directory.files().

Use as you would any other Python iterator. For example:

# set up directory dir, then...
for e in dir.files():
    print('sfile: ', e)

directory_files_iterator Details

class cs.directory_files_iterator

Iterator over the files ( sfile ) immediately contained in a directory ( directory ).

__eq__(other)

Iterator equality.

Parameters:other (directory_files_iterator) –
Return type:bool
Returns:True if and only if self and other are at the same position. Behavior is undefined if self and other are not iterating over the same collection.
>>> cu = next(c for c in project.current().compunits() if c.name().endswith('apitest.cpp'))
>>> sfdir = cu.get_sfileinst().get_sfile().parent()
>>> dirsf_iterA = sfdir.files()
>>> dirsf_iterB = sfdir.files()
>>> dirsf_iterA == dirsf_iterB
True
>>> for d in dirsf_iterA:
...    print(d)              # paths will depend on your local system
...
C:\cygwin\home\alex\testmicros\API\apitest.h
C:\cygwin\home\alex\testmicros\API\apitest.cpp
>>> dirsf_iterA == dirsf_iterB
False
__iter__()

Get the iterator object.

Return type:directory_files_iterator
Returns:self.
>>> v0 = project.current()
>>> v1 = v0.sfiles()
>>> v2 = next(v1)
>>> v3 = v2.parent()
>>> v4 = v3.files()
>>> iter(v4)
<cs.directory_files_iterator begin>
__ne__(other)

Iterator inequality.

Parameters:other (directory_files_iterator) – The iterator to compare against.
Return type:bool
Returns:False if and only if self and other are at the same position. Behavior is undefined if self and other are not iterating over the same collection.
>>> cu = next(c for c in project.current().compunits() if c.name().endswith('apitest.cpp'))
>>> sfdir = cu.get_sfileinst().get_sfile().parent()
>>> dirsf_iterA = sfdir.files()
>>> dirsf_iterB = sfdir.files()
>>> dirsf_iterA != dirsf_iterB
False
>>> for d in dirsf_iterA:
...    print(d)              # paths will depend on your local system
...
C:\cygwin\home\alex\testmicros\API\apitest.h
C:\cygwin\home\alex\testmicros\API\apitest.cpp
>>> dirsf_iterA != dirsf_iterB
True
__next__()

Iterator dereference operator.

Return type:sfile
Returns:The element at the current iterator position.
Raises:StopIteration
  • Side effects: Modifies self.

The typical use is implicit:

>>> for item in myiter:
...   (do something to item)
>>> v0 = project.current()
>>> v1 = v0.sfiles()
>>> v2 = next(v1)
>>> v3 = v2.parent()
>>> v4 = v3.files()
>>> next(v4)
<cs.sfile C:\alex\test\apitest.h>
__repr__()

Get a representation of the iterator that includes information useful for debugging.

Return type:str
Returns:The string representation.
>>> v0 = project.current()
>>> v1 = v0.sfiles()
>>> v2 = next(v1)
>>> v3 = v2.parent()
>>> v4 = v3.files()
>>> repr(v4)
'<cs.directory_files_iterator begin>'
__str__()

Get a simple string representation of the iterator.

Return type:str
Returns:The string representation.
>>> v0 = project.current()
>>> v1 = v0.sfiles()
>>> v2 = next(v1)
>>> v3 = v2.parent()
>>> v4 = v3.files()
>>> str(v4)
'<cs.directory_files_iterator begin>'
at_end()

Check: is the iterator at the end of the structure?

Return type:bool
Returns:True if the iterator is at the end of the structure (there are no more elements to iterate over), False otherwise.
>>> v0 = project.current()
>>> v1 = v0.sfiles()
>>> v2 = next(v1)
>>> v3 = v2.parent()
>>> v4 = v3.files()
>>> v4.at_end()
False