Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [solved]Loading all images from a folder  (Read 1949 times)

0 Members and 1 Guest are viewing this topic.

Ashenwraith

  • Sr. Member
  • ****
  • Posts: 270
    • View Profile
[solved]Loading all images from a folder
« on: April 10, 2010, 07:41:56 am »
Hi, first I'd like to say thanks to Laurent for creating SFML.

I haven't programmed in C++ in many years, but I'm converting my game from Actionscript 3. First I need to convert my tools though.

I have thousands of images that need to be processed so I load them by getting a directory list which returns an array of strings. Next I sort by 'png'.

For example, my code in AS3:
Code: [Select]
var imgs=[];

function Img_Load(path)
{
var f=new File();
f=File.documentsDirectory;
f=f.resolvePath(path);
var l=f.getDirectoryListing(),x=0;

for(var i=0;i<l.length;i++)
{
var s=l[i].nativePath,t=s;
s=s.split('.');
if(s[1]=='png')
{
imgs[x]=t;
x++;
}
}
}


I'm not really sure how I should start with this.

What's the recommended/cross-platform way to get directory listings/work with files?

Should this be a feature I write on my own or should I extend SFML/SOIL?

Shouldn't there be one cross-platform way for all file loading/handling?

EDIT: I just looked at your roadmap, does this do what I'm talking about:

"FS#83 - DataStream framework for resource loading "

http://www.sfml-dev.org/todo/index.php?do=details&task_id=83

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
[solved]Loading all images from a folder
« Reply #1 on: April 10, 2010, 10:43:41 am »
Quote
What's the recommended/cross-platform way to get directory listings/work with files?

boost::filesystem.

Quote
Should this be a feature I write on my own or should I extend SFML/SOIL?

You shouldn't try to rewrite it, it requires low-level code that is specific to the operating system (ie. you will have to write at least 3 versions of the code).

Quote
Shouldn't there be one cross-platform way for all file loading/handling?

Listing files and loading them are two completely unrelated tasks, SFML only cares about loading.
Use boost::filesystem ;)

Quote
EDIT: I just looked at your roadmap, does this do what I'm talking about:

"FS#83 - DataStream framework for resource loading "

No, it is just a way to abstract the source of a resource (can be a file, an array of bytes in memory, a network resource, whatever...).
Laurent Gomila - SFML developer

Ashenwraith

  • Sr. Member
  • ****
  • Posts: 270
    • View Profile
[solved]Loading all images from a folder
« Reply #2 on: April 10, 2010, 03:45:14 pm »
Hey thanks a lot, I'll get working with boost soon.

Yeah, I was just thinking about putting everything together if I had to write it myself.