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 Members¶
| Constructors | none |
| Methods | __eq__(), __iter__(), __ne__(), __next__(), __repr__(), __str__(), at_end() |
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: Trueif and only ifselfandotherare at the same position. Behavior is undefined ifselfandotherare 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_iteratorReturns: 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: Falseif and only ifselfandotherare at the same position. Behavior is undefined ifselfandotherare 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: sfileReturns: 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>
- Side effects: Modifies
-
__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: Trueif the iterator is at the end of the structure (there are no more elements to iterate over),Falseotherwise.>>> v0 = project.current() >>> v1 = v0.sfiles() >>> v2 = next(v1) >>> v3 = v2.parent() >>> v4 = v3.files() >>> v4.at_end() False
-