file.exension not working?
fundies opened this issue · comments
my code gets the file name fine but fails to get the extension
Heres my code:
void get_files(std::string fpath, std::string extension, stringVec &vec)
{
tinydir_dir dir;
if (fpath.back() != '/')
fpath += "/";
tinydir_open_sorted(&dir, fpath.c_str());
for (unsigned i = 0; i < dir.n_files; i++)
{
tinydir_file file;
tinydir_readfile_n(&dir, &file, i);
if (file.is_dir)
{
if (strcmp(file.name, ".") != 0 && strcmp(file.name, "..") != 0)
{
get_files(fpath + file.name + "/", extension, vec);
}
}
else
{
std::cout << "File:" << std::endl;
std::cout << file.name << std::endl;
std::cout << "Extension:" << std::endl;
std::cout << file.extension << std::endl;
if (strcmp(file.extension, extension.c_str()) == 1)
{
std::string resource = fpath + file.name;
vec.push_back(resource);
}
}
}
tinydir_close(&dir);
}
Heres the output:
File:
obj_cheeseboy.hpp
Extension:
File:
room_1.xml
Extension:
File:
sprite_1.xml
Extension:
eboy.hpp
somehow it misses all the extensions and gives me garbage for last one?
Thanks for raising; fixed bug, please try now.