Iterating files with OpenCascade
/ Просмотров: 1374
In the OpenCascade ecosystem, it's pretty handy to rely upon what's called OSD or Operating System Dependent package. This brief blog post is aimed to highlight one technique for working with a filesystem at the lower level without the employment of additional dependencies in software based on OpenCascade.
Here is a code snippet to iterate all files having "tcl" extension in a specific "dir" directory:
OSD_Path path(dir); // for ( OSD_FileIterator fi(path, "*.tcl"); fi.More(); fi.Next() ) { OSD_Path filePath; fi.Values().Path(filePath); TCollection_AsciiString filename; filePath.SystemName(filename); filename = dir + "/" + filename; std::cout << filename.ToCString() << std::endl; }
The advantage of this approach is that you do not need anything but the pure OpenCascade library that you're presumably already using. Personally, I employ this simple technique to execute all Tcl scenarios for the purpose of unit testing.
Want to discuss this? Jump in to our forum.