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
Question regarding directory grabbing..
/**
* 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.
* 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.
-
- Posts: 197
- Joined: Fri Jul 01, 2005 2:50 am
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)
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)