diff --git a/examples/osgvolume/osgvolume.cpp b/examples/osgvolume/osgvolume.cpp index cc07b156f..a7fb0d28a 100644 --- a/examples/osgvolume/osgvolume.cpp +++ b/examples/osgvolume/osgvolume.cpp @@ -1107,11 +1107,29 @@ int main( int argc, char **argv ) int pos=images_pos+1; for(;pos DirectoryContents; -/** return the contents of a directory. - * returns an empty array on any error.*/ +/** Return the contents of a directory. + * Return value will contain filenames only, not absolute paths. + * Returns an empty array on any error.*/ extern OSGDB_EXPORT DirectoryContents getDirectoryContents(const std::string& dirName); - +/** Return the list of filenames that match the given filename with wildcards. + * Will only expand '*', and will not expand wildcards in directory, only in + * filename part of the given filename. + * Return value will contain path+filename so that if ever the above + * limitation (expanding wildcards in directory) is fixed, client code will + * still work unchanged. */ +extern OSGDB_EXPORT DirectoryContents expandWildcardsInFilename(const std::string& filename); namespace FileOpResult { enum Value diff --git a/src/osgDB/FileUtils.cpp b/src/osgDB/FileUtils.cpp index 479089e7f..ede10b99c 100644 --- a/src/osgDB/FileUtils.cpp +++ b/src/osgDB/FileUtils.cpp @@ -530,6 +530,39 @@ static void appendInstallationLibraryFilePaths(osgDB::FilePathList& filepath) #endif // unix getDirectoryContexts +osgDB::DirectoryContents osgDB::expandWildcardsInFilename(const std::string& filename) +{ + osgDB::DirectoryContents contents; + + std::string dir = osgDB::getFilePath(filename); + std::string filenameOnly = filename.substr(dir.length(), std::string::npos); + std::string left = filenameOnly.substr(0, filenameOnly.find('*')); + std::string right = filenameOnly.substr(filenameOnly.find('*')+1, std::string::npos); + + if (dir.empty()) + dir = osgDB::getCurrentWorkingDirectory(); + + osgDB::DirectoryContents dirContents = osgDB::getDirectoryContents(dir); + for (unsigned int i = 0; i < dirContents.size(); ++i) + { + std::string filenameInDir = dirContents[i]; + + if (filenameInDir == "." || + filenameInDir == "..") + { + continue; + } + + if ((filenameInDir.find(left) == 0 || left.empty()) && + (filenameInDir.find(right) == filenameInDir.length() - right.length() || right.empty())) + { + contents.push_back( dir + osgDB::getNativePathSeparator() + filenameInDir ); + } + } + + return contents; +} + osgDB::FileOpResult::Value osgDB::copyFile(const std::string & source, const std::string & destination) { if (source.empty() || destination.empty())