Page 1 of 1

scaning directories?

Posted: Thu Mar 03, 2011 4:27 am
by t377y000
hi im working on a little app for DS & im kinda stuck.
i have the file directories showing. but i kinda need some help scanning trough them like selecting folders & opening/closing them.
sorta like how that one example called all in one where it has a simple menu.

i cant seem to figure it out

my code is similar to the libfat code.
but how to surch trugh directories it shows?

Re: scaning directories?

Posted: Thu Mar 03, 2011 2:08 pm
by elhobbs
can you be a little more specific - I am not sure what you are asking. can you show what you are trying to do, how you are trying to do it, and why you think it is not working?

Re: scaning directories?

Posted: Thu Mar 03, 2011 4:10 pm
by lazyprogramer
can you be a little more specific - I am not sure what you are asking.
I think he meant he wants the source code for open a directory (folder) and to show the filenames in this directory (folder).

Re: scaning directories?

Posted: Sat Mar 05, 2011 8:03 am
by t377y000
lazyprogramer wrote:
can you be a little more specific - I am not sure what you are asking.
I think he meant he wants the source code for open a directory (folder) and to show the filenames in this directory (folder).
yes exactly that, sorry wasnt so spacific,
like i have the code where the folder directories are showing. but im having problems comming up with something to look trugh the folders.
heres the code

Code: Select all

//---------------------------------------------------------------------------------
int main(int argc, char **argv) {
//---------------------------------------------------------------------------------
	
	videoSetMode(MODE_0_2D);
	videoSetModeSub(MODE_0_2D);
	
	PrintConsole topScreen;
	vramSetBankA(VRAM_A_MAIN_BG);
	consoleInit(&topScreen, 0,BgType_Text4bpp, BgSize_T_256x256, 31, 0, true, true);
	PrintConsole bottomScreen;
	consoleSelect(&topScreen);
	//1-7 after 3 for color
	iprintf("\x1b[34;1miLauncher 000\n");
	
	vramSetBankC(VRAM_C_SUB_BG);
	consoleInit(&bottomScreen, 0,BgType_Text4bpp, BgSize_T_256x256, 31, 0, false, true);
	BG_PALETTE_SUB[0] = RGB15( 0, 0, 20 );
	consoleSelect(&bottomScreen);
	
	
	
	if (fatInitDefault())
	{
		DIR *pdir; 
		
		struct dirent *pent;
		struct stat statbuf;
		
		pdir=opendir("/");

		if (pdir)
		{
			while ((pent=readdir(pdir))!=NULL) 
			{
				stat(pent->d_name,&statbuf);
	    		if(strcmp(".", pent->d_name) == 0 || strcmp("..", pent->d_name) == 0)continue;
	
	    		if(S_ISDIR(statbuf.st_mode))
	        		iprintf("%s <dir>\n", pent->d_name);
	    		if(!(S_ISDIR(statbuf.st_mode)))
	        		iprintf("%s %ld\n", pent->d_name, statbuf.st_size);
		
					
			}
			closedir(pdir);
		} 
		
		
		
		else
		{
		iprintf("opendir() failure; terminating\n");
		}

	} 
	
	//if fails
	else 
	{
	iprintf("fatInitDefault failure: terminating\n");
	}



	while(1) {
		
		//swiWaitForVBlank();
	}

	return 0;
}

Re: scaning directories?

Posted: Sat Mar 05, 2011 11:04 am
by lazyprogramer
Sorry can you please post your hole source and maybe your Makefile, because compiling this short piece of code isn't possible!

Re: scaning directories?

Posted: Sat Mar 05, 2011 6:44 pm
by ed.gregory
Hi. It might be worth your while looking at devkitpro/examples/nds/filesystem/nitrofs and libfat.
The nitrofs example seems to fill your requirement.

Re: scaning directories?

Posted: Sun Mar 06, 2011 8:16 am
by t377y000
lazyprogramer wrote:Sorry can you please post your hole source and maybe your Makefile, because compiling this short piece of code isn't possible!
sorry heres the while source , & te makefile is from arm 9 template

Code: Select all

/*---------------------------------------------------------------------------------

	Basic template code for starting a DS app

---------------------------------------------------------------------------------*/
#include <nds.h>
#include <fat.h>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
#include <unistd.h>


//---------------------------------------------------------------------------------
int main(int argc, char **argv) {
//---------------------------------------------------------------------------------
	
	videoSetMode(MODE_0_2D);
	videoSetModeSub(MODE_0_2D);
	
	PrintConsole topScreen;
	vramSetBankA(VRAM_A_MAIN_BG);
	consoleInit(&topScreen, 0,BgType_Text4bpp, BgSize_T_256x256, 31, 0, true, true);
	PrintConsole bottomScreen;
	consoleSelect(&topScreen);
	//1-7 after 3 for color
	iprintf("\x1b[34;1miLauncher 000\n");
	
	vramSetBankC(VRAM_C_SUB_BG);
	consoleInit(&bottomScreen, 0,BgType_Text4bpp, BgSize_T_256x256, 31, 0, false, true);
	BG_PALETTE_SUB[0] = RGB15( 0, 0, 20 );
	consoleSelect(&bottomScreen);
	
	
	
	if (fatInitDefault())
	{
		DIR *pdir; 
		
		struct dirent *pent;
		struct stat statbuf;
		
		pdir=opendir("/");

		if (pdir)
		{
			while ((pent=readdir(pdir))!=NULL) 
			{
				stat(pent->d_name,&statbuf);
	    		if(strcmp(".", pent->d_name) == 0 || strcmp("..", pent->d_name) == 0)continue;
	
	    		if(S_ISDIR(statbuf.st_mode))
	        		iprintf("%s <dir>\n", pent->d_name);
	    		if(!(S_ISDIR(statbuf.st_mode)))
	        		iprintf("%s %ld\n", pent->d_name, statbuf.st_size);
		
					
			}
			closedir(pdir);
		} 
		
		
		
		else
		{
		iprintf("opendir() failure; terminating\n");
		}

	} 
	
	//if fails
	else 
	{
	iprintf("fatInitDefault failure: terminating\n");
	}



	while(1) {
		
		//swiWaitForVBlank();
	}

	return 0;
}

Re: scaning directories?

Posted: Sun Mar 06, 2011 10:41 am
by lazyprogramer
Well, it seems that you changed the Makefile a bit:

Code: Select all

LIBS	:= 	-lfat -lnds9 
You have to add the libfat in your makefile right?

I will test your app now...

Re: scaning directories?

Posted: Sun Mar 06, 2011 11:08 am
by t377y000
lazyprogramer wrote:Well, it seems that you changed the Makefile a bit:

Code: Select all

LIBS	:= 	-lfat -lnds9 
You have to add the libfat in your makefile right?

I will test your app now...
yes i added those