Array with filenames from given path(Directory)

I think the question is pretty self-explanatory. I want to create a custom Blueprint Node with a path to a directory as input and a array with the file/directory-names in that directory as output.

After a bit of research i found out that i need to use IterateDirectory() but I’m new to C++ and don’t know to use it.

Thanks :slight_smile:

It’s kind of odd iterator it seems, i didnt do that myself, i just got this from looking at engine source code, so there might be error, but try it

You need to create subclass class that implements IFilePlatfrom::FDirectoryVisitor which will implement Visit(const TCHAR * FilenameOrDirectory, bool bIsDirectory); and then you call IterateDirectory() with instance of a object that imlements FDirectoryVisitor. IterateDirectory() will call visit function for each directory and file in directory until Visit function will return false or there wont be any files to iterate. You can actully declere local visitor class inside the function to make things look cleaner ;]

bool USomeClass::DoSomethingBigOnFiles(const TCHAR* Directory)
{
	class FMyVisitor : public FDirectoryVisitor
	{
	public:
		FMyVisitor()
		{
		}
		virtual bool Visit(const TCHAR* Filename, bool bIsDirectory)
		{
			if (bIsDirectory)
			{
				DoSomethingToDirectory(Filename);
			}
			else
			{
                DoSomethingToFile(Filename);
			}
			return true; // continue searching
		}
	};
	FMyVisitor MyVistor();
	return IterateDirectory(Directory, MyVisitor);
	
}

You can make constructor to have a arguments too. Again i deduced that from looking at engine source code so something might not be correct, look it up yourself:

/EpicGames/UnrealEngine/search?utf8=%E2%9C%93&q=IterateDirectory&type=Code

Here example of recursive file delete:

Thanks a lot :slight_smile: