Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

file.exension not working? #9

Closed
fundies opened this issue Apr 13, 2014 · 1 comment
Closed

file.exension not working? #9

fundies opened this issue Apr 13, 2014 · 1 comment

Comments

@fundies
Copy link

fundies commented Apr 13, 2014

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?

@cxong cxong closed this as completed in 68983ed Apr 13, 2014
@cxong
Copy link
Owner

cxong commented Apr 13, 2014

Thanks for raising; fixed bug, please try now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants