File list. Recursively searching folders.

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.

Re: File list. Recursively searching folders.

Postby Sidar » Sun May 13, 2012 10:59 pm

Like I said before, the method had no problem finding my file in a SUBFOLDER. Even now that seems to stop working even though I didn't change anything.
Sidar
 
Posts: 13
Joined: Sat May 12, 2012 11:12 pm

Re: File list. Recursively searching folders.

Postby REDDemon » Sun May 13, 2012 11:12 pm

sorry but you are not getting the point.

filelist only owns this files.
cpp Code: Select all
 
u32 max=filelist->getFileCount();
(u32 i=0; i<max; i++)
{
    cout<<filelist->getFileName(i).c_str()<<endl;
}
 


it is obvious that if file list has following files

folder/a.png
folder/b.png
folder/c.png

it is not able to find

folder/folder/a.png

because since you are concatenating filenames you are exactly trying to search for files that are not in filelist. As already sad your problem is that filelist->Findfile
was returning -1. I just pointed you because findfile was returning -1.

If you want really to find "folder/folder/a.png" you should find someway to add that file to the filelist (initializing correctly the file list could be a way, you can add later all paths i thnik also) or to use another filelist, because filelist is not automagically updating its content. It's just a list (of files but nothing more than a list).

so the first thing you need to see is what files are inside filelist. You will know this way if the problem is the filelist or something else
OpenGL is not hard. What you have to do is just explained in specifications. What is hard is dealing with poor OpenGL implementations.
User avatar
REDDemon
 
Posts: 831
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

Re: File list. Recursively searching folders.

Postby Sidar » Sun May 13, 2012 11:24 pm

Yeah I figured that much.

This is hopeless I'm working on this far too long. All I really wanted is to look for a file in a given path and all it's subfolders.
But I can't figure it out.

I guess I have to try a different approach.
thanks anyways.


Edit:

Removed the Irrlicht filelist and just went with the windows API.

cpp Code: Select all
irr::video::ITexture * TextureManager::findInPath(irr::io::path path,irr::io::path filename){
 
        irr::video::ITexture * t = NULL;
        irr::io::path dir(path);
        dir.append("*");
        WIN32_FIND_DATA file;
        HANDLE search_handle=FindFirstFile(LPCTSTR(dir.c_str()),&file);
 
       
        if (search_handle)
        {
 
                do
                {
                        irr::io::path resultPath;
                        if (file.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
                        {
                               
                                //Skip any reference to current or parent folder. Else inf-loop imminent
                                if(file.cFileName[0] == '.'){
                                        continue;
                                }
                                        t = findInPath(path+file.cFileName + "/",filename);
                                        if(t) return t;
                        }
                        else
                        {
                               
                                irr::io::path sfile(file.cFileName);
 
                                std::cout << sfile.c_str();
 
                                if(sfile.equals_ignore_case(filename) == true)
                                {
 
                                        resultPath = path + filename;  
                                        t = driver->getTexture(resultPath);
                                        return t;
                                }
                        }
 
                }while(FindNextFile(search_handle,&file));
 
                FindClose(search_handle);
 
        }
        return t;
};


This works.
Now if only I could find a way to sort the items on files first.
Sidar
 
Posts: 13
Joined: Sat May 12, 2012 11:12 pm

Re: File list. Recursively searching folders.

Postby Sidar » Mon May 14, 2012 12:10 am

I tried changing work directory before my solution, it gave all sort of problems with other objects trying to find files.
Of course it's just me not fully grasping everything in C++ and such.

Here is slightly better "solution" with the win32 api.

cpp Code: Select all
irr::video::ITexture * TextureManager::findInPath(irr::io::path path,irr::io::path filename){
 
        irr::video::ITexture * t = NULL;
        irr::io::path dir(path);
        dir.append("*");
 
        irr::io::path currDir(path);
        currDir.append(filename.c_str());
 
        WIN32_FIND_DATA file;
        HANDLE search_handle=FindFirstFile(LPCTSTR(dir.c_str()),&file);
        irr::io::path resultPath;
 
        if(GetFileAttributes(LPCTSTR(currDir.c_str())) != 0xFFFFFFFF)
        {
                resultPath = path + filename;  
                t = driver->getTexture(resultPath);
                return t;
        }
 
        else if (searchRecursively == true && search_handle)
        {
                do
                {
                       
                        if (file.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
                        {
                               
                                //Skip any reference to current or parent folder. Else inf-loop imminent
                                if(file.cFileName[0] == '.')
                                {
                                        continue;
                                }
                                        t = findInPath(path+file.cFileName + "/",filename);
                                        if(t) return t;
                        }
               
                }while(FindNextFile(search_handle,&file));
 
                FindClose(search_handle);
 
        }
        return t;
};


It first checks if the file im looking for exists in the folder, then it continues iterating over every folder and calls itself again.

Thanks for the help though. But for now this will suffice =D

Edit:
Why did you delete your post?
Others could have benefit from the irrlicht solution!
Sidar
 
Posts: 13
Joined: Sat May 12, 2012 11:12 pm

Previous

Return to Beginners Help

Who is online

Users browsing this forum: No registered users and 1 guest