Download

Find files by extension? IFileManager::FindFilesRecursive()

I need to find all files with a .fbx extension in a given folder.

I have found this function:


 IFileManager::FindFilesRecursive()
 

and i have this:


 IFileManager *x = NULL;
     const TCHAR* RootPath = _T("D:/assets/test");
     TArray<FString> Files;
     const TCHAR* extension = _T("*.fbx");
     x->FindFilesRecursive(Files, RootPath, extension, true, false, false);

when I run the code, it breaks on:


 x->FindFilesRecursive(Files, RootPath, extension, true, false, false);

with an ‘unhandled exception / access violation reading location’.

Where am I going wrong here?

Thanks.

You’re never initializing ‘x’, so it’s a nullptr dereference by the looks of it.

Ignore creating the pointer to IFileManager, just call IFileManager::FindFilesRecursive instead.

Thanks for your reply.


IFileManager::FindFilesRecursive(Files, RootPath, extension, true, false, false);

gives me the error:

‘a nonstatic member reference must be relative to a specific object’.

Okay yeah scratch my previous post then, FindFilesRecursive isn’t static so you need an IFileManager. Try this:



 IFileManager* _FileManager = IFileManager::Get();
     const TCHAR* RootPath = _T("D:/assets/test");
     TArray<FString> Files;
     const TCHAR* extension = _T("*.fbx");
     _FileManager->FindFilesRecursive(Files, RootPath, extension, true, false, false);


Works like a dream. Many thanks yet again!

No Problem :stuck_out_tongue:

I tried this and got an error "error C2440: ‘initializing’: cannot convert from ‘IFileManager’ to ‘IFileManager *’ ". How do I fix this?

If you look at the code in VS you will find that the static getter returns a ref now, so:



 IFileManager::Get().FindFilesRecursive()