How do I get documents filepath?

Hello.

As the title says, I’d like to get the documents filepath, and then get files from documents(text files) with FFileManagerGeneric::FindFiles(). I tried looking at FPaths, but I couldn’t find anything.

Any ideas on how I should do this?

Hi,

You aren’t really clear on what documents file path are you looking for?

For example you could get directory where projects are with:

const TCHAR* FGenericPlatformProcess::UserDir()

Or are you looking to just browse the file system anywhere (this could be a problem depending on the system permissions, so needs to accounted for)?

Perhaps the problem you had with FFileManagerGeneric was that of relative vs absolute path?

You are probably best of working with relative paths (relative to the Engine root) so that your code works on all platforms.

I just wanted to have some files in My Documents that I would load at runtime.

Then use UserDir() method to get the right path to it.

Hm, FGenericPlatformProcess::UserDir() seems to lead to “C:/Program Files/Epic Games/4.6/” (this is what I get Screenshot - e26e475d1890b6a87f6daaf2e9918bea - Gyazo ).

I think that should’ve been FPlatformProcess::UserDir() instead - sorry about that.

It works! Thanks for the help man, I really appreciate it. :slight_smile:

EDIT: One more question, do you have any idea how to load .png files into a UTexture array (from My Documents as well)?

Check this page, perhaps that’s what you are looking for: Asynchronous Asset Loading | Unreal Engine Documentation else see this answer: https://answers.unrealengine.com/questions/23440/loading-textures-at-runtime.html

Hm, I can’t seem to find out how to get a .png loaded as a UTexture. :frowning:

I tried to use some of those examples, but with no luck.

Did you check the second link to the answer I linked above?

It has a code snippet by Dune that loads a UTexture2D by specifying a path to it. That should work, but beware of the caveat mentioned in there as well regarding cooking content.

Are you sure you can load .png files from My Documents with that code? I tried it and it didn’t seem to work. :frowning:

Are you sure that you can load .png files from My Documents with that code? I tried it and it didn’t seem to work. :frowning:

It might be an issue with relative vs full paths, but to be honest I am not sure whether arbitrary loading from any folder is allowed. Although you are loading from UserDir() value, so it should work.

Take a look for example at SpeedTree importer, they are loading textures and seem to have some path conversions: Engine/Plugins/Editor/SpeedTreeImporter/Source/SpeedTreeImporter/Private/SpeedTreeImportFactory.cpp

I’m not currently subscribed to UE (I’ll resub when 4.7 is out), and I don’t have the source at the moment. Any chance you could show me the code? :slight_smile:

We are only allowed posting a limited number of lines for discussion, and I think you need to take a look a the whole of the Import Factory to get the scope of it.

If you have old code from when you were subscribed, you could probably look at other parts of the engine, where levels or materials are loaded, they must use the same methods.

Alright, I’ll do that. Thanks. :slight_smile: