File list. Recursively searching folders.
Re: File list. Recursively searching folders.
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.
Re: File list. Recursively searching folders.
sorry but you are not getting the point.
filelist only owns this files.
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
filelist only owns this files.
Code: Select all
u32 max=filelist->getFileCount();
(u32 i=0; i<max; i++)
{
cout<<filelist->getFileName(i).c_str()<<endl;
}
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
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
Re: File list. Recursively searching folders.
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.
This works.
Now if only I could find a way to sort the items on files first.
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.
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;
};
Now if only I could find a way to sort the items on files first.
Re: File list. Recursively searching folders.
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.
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!
Of course it's just me not fully grasping everything in C++ and such.
Here is slightly better "solution" with the win32 api.
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;
};
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!