No, i don't think it will work, you are kinda hardcoding the number of images, you dont need to.
There is a way that you load ALL the images in there, no matter the format, i'll try to describe it, but notice you must be careful as you might end trying to load another file type into sf::Image. Make sure there are only images in the directory you're selecting : )
About the sprites, you shouldn't do what you are doing, you are creating one sprite per image, instead , store only the images and no sprites.
And in the game, whenever you need the sprite you create it, or even create them all at initialization, just associate the sprites with images when you need the sprites, not on image loading time, this way you can use the same image for many sprites, and save resources : )
Write a function like this:
void ResourceManager::LoadImages(string Directory){
WIN32_FIND_DATAA File; //Info about the file to read
HANDLE FindHandle = INVALID_HANDLE_VALUE; //Handle to find files
FindHandle = FindFirstFileA(string(Directory + "\\*.*")), &File); //find the first file in the directory(parameter 1) and store in file(parameter 2)
if(FindHandle == INVALID_HANDLE_VALUE)
return; //return because there was NO first file
//By now, you have the first file
string FileName = File.cFileName;
//You HAVE to make sure it is a valid file, because the special directories "." and ".." may appear!
//In case you obtained a good file, load it :)
//Also, directories will be counted as files! so, they will appear!
//No subfolders where you are reading : )
if(FileName != "." && FileName != ".."){
sf::Image img;
img.LoadFromFile(FileName);
ImageList.insert(ImageList.end(), &img);
}
//For the rest of files
while(FindNextFileA(FindHandle, &File)){
FileName = FileData.cFileName;
//Same verifications as the first file, and then load, pretty much the same
}
//Close handles
FindClose(FindHandle);
}
Finish the function by yourself, make sure you understand, even try to make it more powerful, by googling and exploring more properties!
Hint: try to make it recursive if you need it : )