Skip to content

Commit

Permalink
Helper method to obtain file name from a given path. Refs #7636.
Browse files Browse the repository at this point in the history
  • Loading branch information
jawrainey committed Dec 12, 2013
1 parent e28c983 commit 08f41c1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Code/Mantid/Framework/ICat/inc/MantidICat/CatalogPublish.h
Expand Up @@ -55,6 +55,8 @@ namespace Mantid
void exec();
/// True if the extension of the file is a datafile.
bool isDataFile(const std::string & filePath);
/// Extracts the file name (e.g. CSP74683_ICPevent) from the file path.
const std::string extractFileName(const std::string &filePath);
};
}
}
Expand Down
13 changes: 13 additions & 0 deletions Code/Mantid/Framework/ICat/src/CatalogPublish.cpp
Expand Up @@ -94,5 +94,18 @@ namespace Mantid
return extension.compare("raw") == 0 || extension.compare("nxs") == 0;
}

/**
* Extract the name of the file from a given path.
* @param filePath :: Path of data file to use.
* @returns The filename of the given path
*/
const std::string CatalogPublish::extractFileName(const std::string &filePath)
{
// Extracts the file name (e.g. CSP74683_ICPevent) from the file path.
std::string dataFileName = Poco::Path(Poco::Path(filePath).getFileName()).getBaseName();
// Extracts the specific file name (e.g. CSP74683) from the file path.
return dataFileName.substr(0, dataFileName.find_first_of('_'));
}

}
}

0 comments on commit 08f41c1

Please sign in to comment.