BCS Boost List Of File Specifications


Boost handles retrieving file specifications. Our routine allows for the fully qualified file specification or just the filename and extension.  We begin by telling c++ we are using boost.
[codesyntax lang=”cpp”]

#include <boost/filesystem.hpp>
using namespace boost::filesystem;

[/codesyntax]
The actual Boost snippet is as follows.
[codesyntax lang=”cpp”]

void retFiles(path p, bool fqp) {
	for (auto i = directory_iterator(p); i != directory_iterator(); i++) {
		if (!is_directory(i->path())) //we eliminate directories
				{
			string zfs;
			if (fqp) {
				zfs = i->path().string();
			} else {
				zfs = i->path().filename().string();
			}
			cout << zfs << endl;
		} else
			continue;
	}
}

[/codesyntax]
Finally our calling sequence would appear as follows.
[codesyntax lang=”cpp”]

	retFiles("/home/archman/workspace/xw/Tes08/src", false);

[/codesyntax]
The fqp Boolean allows the user to user the fully qualified path and the file specification or just the filename extension version of the file specification.
Mr. Arch Brooks, Software Engineer, Brooks Computing Systems, LLC authored this article.

Leave a Reply

Your email address will not be published. Required fields are marked *