(HTTP Request) Write each file with a different name upon downloading

I’ve created a downloader that downloads many files from a server at the same time. The problem that I’m having right now is my downloader overwrites a newer file with the old file that has been downloaded. Currently I have named every file “File” in my code after downloading, but I want my downloader to write/download the files in this pattern like “File0” “File1”, “File2” and so on. How can I get my downloader to write the files in this pattern “File0” “File1”, “File2”? More like increment the file “File” number.

I did a bit of research on it and it seems like listing files from a directory is possible, you could either copy paste the code found in this answer and get how many items are in the TArray (with .Num() ) or you could remove most of the unnecessary code for you and supply use the logic in there to increment a number.

Once you have your number you can simply use FString::Printf(TEXT("File_%d.txt"), YourNumberOfFilesAsAnInt) instead of "File" + ".txt" which btw is platform dependent and you should be using TEXT for

A second solution could be simply having a counter in the class of the downloader itself and using the same formatting method above, however if you use multi threading or if you think there could be multiple threads downloading at once this could potentially lead to issues (i.e. two threads reading it at once), you can use the same formatting option as above to get the counter into an FString

Edit: Forgot to add the link https://answers.unrealengine.com/questions/212791/how-to-get-file-list-in-a-directory.html