Need function that can print out the content of a dir

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
Ghozt
Posts: 34
Joined: Mon Mar 13, 2006 8:37 pm

Need function that can print out the content of a dir

Post by Ghozt »

Hi everybody!

I need a function that can print out the content of a dir (eg. ms0:/PSP/GAME/MYPROGRAM/STUFF/"). Then I want the user to be able to select one of the files/dirs in the folder (like in a menu) and then my app will copy a file from the selected dir to another dir (I already have made the copy file function).

eg. There is two folders in the "STUFF" folder called "EXTRA1" and "EXTRA2". The functions should then print out the content of the "STUFF" folder (in other words, it should print out EXTRA1 and EXTRA2) to the screen, and then the user should select one, let's say "EXTRA2". Then my copy function called copy_file is going to copy a file from the extra2 folder to another dir. eg. copy_file("ms0:/PSP/GAME/PROGRAM/STUFF/"selectedDir, "[insert a copy-to dir here]");
The selectedDir should be the Dir selected.

I hope you all understand what I mean. Thanks in advance!
User avatar
dot_blank
Posts: 498
Joined: Wed Sep 28, 2005 8:47 am
Location: Brasil

Post by dot_blank »

yes this is all very easy ....search online for dir handling
dirent.h is a good start and please do finish any
standard C book :P ...as most touch upon file io
pretty much extensively ...you could also look into
the source of RIN gameboy emu that has dir handling
10011011 00101010 11010111 10001001 10111010
Ghozt
Posts: 34
Joined: Mon Mar 13, 2006 8:37 pm

Post by Ghozt »

I just wonderd if anyone had any good and easy to use examples laying around.
Art
Posts: 642
Joined: Wed Nov 09, 2005 8:01 am

Post by Art »

There is a tool in samples to DUMP all files in a directory,
why not use it to print the filenames to screen instead?
Sorry , I don't have exactly what you want, but that's where I'd start.
AnonymousTipster
Posts: 197
Joined: Fri Jul 01, 2005 2:50 am

Post by AnonymousTipster »

Ok, this is a code snippet from my .zip extractor. It reads PSP/GAME and reads every entry into a string:

Code: Select all

struct GameEntry
{
	char *name;
	//char ratio[16];
};

int gameEntriesTotal = 0;
int gameDirSelected = 0;

#define MAX_ENTRIES 1000

struct GameEntry gameEntry[MAX_ENTRIES];

void recacheGameDir(){
struct SceIoDirent dir;
	memset(&dir, 0, sizeof(SceIoDirent)); 
	pspDebugScreenSetXY(0,6);
	//printf("Getting Directory...");
	static int dfd;
	dfd = sceIoDopen("ms0:/PSP/GAME/");
	if(dfd > 0){
	//pspDebugScreenSetXY(0,0);
	//printf("Found Directory...\n");
	int f=0;for&#40;f=0;f<MAX_ENTRIES;f++&#41;&#123;if&#40;gameEntry&#91;f&#93;.name&#41;&#123;free&#40;gameEntry&#91;f&#93;.name&#41;;&#125;gameEntry&#91;f&#93;.name = NULL;&#125;
	int count = 0;count = 0;
	
	while&#40;sceIoDread&#40;dfd, &dir&#41; > 0&#41;&#123;
	static int success;
	//success = sceIoDread&#40;dfd, dir&#41;;
	//if&#40;dir&#41;&#123;
	static char* name;
	name = &#40;char*&#41;memalign&#40;16,300&#41;;
	sprintf&#40;name,"%s",dir.d_name&#41;;
	static int s=0;
	s=strlen&#40;name&#41;;
	
	//printf&#40;"Found&#58; %s\n",name&#41;;
	gameEntry&#91;count&#93;.name = name;
	
		count++;if&#40;count>MAX_ENTRIES-1&#41;&#123;count = MAX_ENTRIES-1;&#125;
	//printf&#40;"COUNT&#58; %i",count&#41;;
	gameEntriesTotal = count;if&#40;gameEntriesTotal < 0&#41;&#123;gameEntriesTotal = 0;&#125;
	&#125;
	
	//&#125;
	&#125;
	sceIoDclose&#40;dfd&#41;;
	//sceKernelThreadSleep&#40;10000&#41;;
	//free&#40;&dir&#41;;
&#125;
This should leave you with a list of strings, each containing a folder or file name.
Hope this helps somewhat.
RCON
Posts: 16
Joined: Wed Aug 03, 2005 1:02 am
Contact:

Post by RCON »

AnonymousTipster wrote:Hope this helps somewhat.
That code ROCKS! Works perfectly!
Post Reply