forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Need function that can print out the content of a dir

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
Ghozt



Joined: 13 Mar 2006
Posts: 34

PostPosted: Wed Jun 07, 2006 5:47 am    Post subject: Need function that can print out the content of a dir Reply with quote

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!
Back to top
View user's profile Send private message
dot_blank



Joined: 28 Sep 2005
Posts: 498
Location: Brasil

PostPosted: Wed Jun 07, 2006 6:13 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
Ghozt



Joined: 13 Mar 2006
Posts: 34

PostPosted: Wed Jun 07, 2006 6:53 am    Post subject: Reply with quote

I just wonderd if anyone had any good and easy to use examples laying around.
Back to top
View user's profile Send private message
Art



Joined: 09 Nov 2005
Posts: 647

PostPosted: Wed Jun 07, 2006 7:27 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
AnonymousTipster



Joined: 01 Jul 2005
Posts: 197

PostPosted: Wed Jun 07, 2006 7:54 am    Post subject: Reply with quote

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

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(f=0;f<MAX_ENTRIES;f++){if(gameEntry[f].name){free(gameEntry[f].name);}gameEntry[f].name = NULL;}
   int count = 0;count = 0;
   
   while(sceIoDread(dfd, &dir) > 0){
   static int success;
   //success = sceIoDread(dfd, dir);
   //if(dir){
   static char* name;
   name = (char*)memalign(16,300);
   sprintf(name,"%s",dir.d_name);
   static int s=0;
   s=strlen(name);
   
   //printf("Found: %s\n",name);
   gameEntry[count].name = name;
   
      count++;if(count>MAX_ENTRIES-1){count = MAX_ENTRIES-1;}
   //printf("COUNT: %i",count);
   gameEntriesTotal = count;if(gameEntriesTotal < 0){gameEntriesTotal = 0;}
   }
   
   //}
   }
   sceIoDclose(dfd);
   //sceKernelThreadSleep(10000);
   //free(&dir);
}
This should leave you with a list of strings, each containing a folder or file name.
Hope this helps somewhat.
Back to top
View user's profile Send private message
RCON



Joined: 03 Aug 2005
Posts: 16

PostPosted: Sun Jun 11, 2006 12:11 pm    Post subject: Reply with quote

AnonymousTipster wrote:
Hope this helps somewhat.


That code ROCKS! Works perfectly!
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group