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 

Question regarding directory grabbing..

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



Joined: 26 Dec 2005
Posts: 42

PostPosted: Sat Oct 14, 2006 4:20 pm    Post subject: Question regarding directory grabbing.. Reply with quote

Hello guys, what is an easy way of reading a directory in on the mem stick so I can get the list of files to load into my program?

cheers,
zshadow
Back to top
View user's profile Send private message
weltall



Joined: 20 Feb 2004
Posts: 310

PostPosted: Sun Oct 15, 2006 1:08 am    Post subject: Reply with quote

/**
* Open a directory
*
* @par Example:
* @code
* int dfd;
* dfd = sceIoDopen("device:/");
* if(dfd >= 0)
* { Do something with the file descriptor }
* @endcode
* @param dirname - The directory to open for reading.
* @return If >= 0 then a valid file descriptor, otherwise a Sony error code.
*/
SceUID sceIoDopen(const char *dirname);

/**
* Reads an entry from an opened file descriptor.
*
* @param fd - Already opened file descriptor (using sceIoDopen)
* @param dir - Pointer to an io_dirent_t structure to hold the file information
*
* @return Read status
* - 0 - No more directory entries left
* - > 0 - More directory entired to go
* - < 0 - Error
*/
int sceIoDread(SceUID fd, SceIoDirent *dir);

/**
* Close an opened directory file descriptor
*
* @param fd - Already opened file descriptor (using sceIoDopen)
* @return < 0 on error
*/
int sceIoDclose(SceUID fd);

/** Describes a single directory entry */
typedef struct SceIoDirent {
/** File status. */
SceIoStat d_stat;
/** File name. */
char d_name[256];
/** Device-specific data. */
void * d_private;
int dummy;
} SceIoDirent;

remember to memset to 0 sceiodirent every time you read a new directory entry.
Back to top
View user's profile Send private message Visit poster's website
AnonymousTipster



Joined: 01 Jul 2005
Posts: 197

PostPosted: Sun Oct 15, 2006 1:23 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.

(Yes, this is a duplicate of a post I made some time earlier)
Back to top
View user's profile Send private message
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