我有一堆名为 Apple-1、...、Apple-n 的图像,但我不知道 Apple-x 是 .jpeg 还是 .png,我想在不知道它是 .jpeg 什么的情况下确定它别的。
我所知道的是图像是如何标记的,我想将它们的扩展名放入一个字符串中(不是全部都在一个字符串中,我会检查每张图片)。我很欣赏任何想法:)
(这里问了一个类似的问题,但那是针对 C#: Get extension of file without provide extension in the path)
我有一堆名为 Apple-1、...、Apple-n 的图像,但我不知道 Apple-x 是 .jpeg 还是 .png,我想在不知道它是 .jpeg 什么的情况下确定它别的。
我所知道的是图像是如何标记的,我想将它们的扩展名放入一个字符串中(不是全部都在一个字符串中,我会检查每张图片)。我很欣赏任何想法:)
(这里问了一个类似的问题,但那是针对 C#: Get extension of file without provide extension in the path)
你可以很容易地做到这一点boost::filesystem
:
例子
boost::filesystem::path folder(boost::filesystem::current_path());
for (boost::filesystem::directory_iterator it(folder), end;
it != end; ++it)
{
auto ext = it->path().extension();
if (ext == ".jpeg")
{
std::cout << "is jpeg" << std::endl;
}
}
boost 文件系统库为此和相关的路径问题提供了一组出色的函数”,请参见此处