scaning directories?

Post Reply
t377y000
Posts: 53
Joined: Wed Jun 02, 2010 3:14 am
Location: United States

scaning directories?

Post by t377y000 » Thu Mar 03, 2011 4:27 am

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?

elhobbs
Posts: 358
Joined: Thu Jul 02, 2009 1:19 pm

Re: scaning directories?

Post by elhobbs » Thu Mar 03, 2011 2:08 pm

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?

lazyprogramer
Posts: 85
Joined: Mon Sep 27, 2010 5:26 pm

Re: scaning directories?

Post by lazyprogramer » Thu Mar 03, 2011 4:10 pm

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).

t377y000
Posts: 53
Joined: Wed Jun 02, 2010 3:14 am
Location: United States

Re: scaning directories?

Post by t377y000 » Sat Mar 05, 2011 8:03 am

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;
}

lazyprogramer
Posts: 85
Joined: Mon Sep 27, 2010 5:26 pm

Re: scaning directories?

Post by lazyprogramer » Sat Mar 05, 2011 11:04 am

Sorry can you please post your hole source and maybe your Makefile, because compiling this short piece of code isn't possible!

ed.gregory
Posts: 1
Joined: Fri Jul 09, 2010 4:16 pm

Re: scaning directories?

Post by ed.gregory » Sat Mar 05, 2011 6:44 pm

Hi. It might be worth your while looking at devkitpro/examples/nds/filesystem/nitrofs and libfat.
The nitrofs example seems to fill your requirement.

t377y000
Posts: 53
Joined: Wed Jun 02, 2010 3:14 am
Location: United States

Re: scaning directories?

Post by t377y000 » Sun Mar 06, 2011 8:16 am

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;
}

lazyprogramer
Posts: 85
Joined: Mon Sep 27, 2010 5:26 pm

Re: scaning directories?

Post by lazyprogramer » Sun Mar 06, 2011 10:41 am

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...

t377y000
Posts: 53
Joined: Wed Jun 02, 2010 3:14 am
Location: United States

Re: scaning directories?

Post by t377y000 » Sun Mar 06, 2011 11:08 am

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

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests