Folder Listing


PokeParadox

Founder of Pirate Games - Penjin Coder
Staff member
Joined
Dec 8, 2005
Messages
6,603
Age
40
Location
UK
Website
pokeparadox.itch.io
WEBSITE
https://github.com/pokeparadox
YOUTUBE
pokeparadox
OK, I working on a project, and I need to generate a list of directories in a specific folder.

How would I go about doing this in C++?

e.g. I have

c:\Project\data\characters
which has several folder inside for each character in the game
Each character folder has a script on how to represent the character in game, and all the image resources to display the character, etc.

The above example is windows based, but I intend on brnging this project to the GP2X also. :)

As usual, any help appreciated.
 
For the GP2X this will print out a list of directories.

Note: The are not in any particular order you probably want to put the directories in a STL list and sort then.

Code:
#include <sys/types.h>
#include <dirent.h>
#include <iostream>

using namespace std;

int main(int argc, char** argv)
{
	DIR* dp = opendir(".");
	dirent *dep;

	while ((dep = readdir(dp)) != NULL)
	{
	if (dep->d_type == DT_DIR)
	{
		cout << dep->d_name << endl;
	}
	}
}
 
Back
Top