 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
zshadow
Joined: 26 Dec 2005 Posts: 42
|
Posted: Sat Oct 14, 2006 4:20 pm Post subject: Question regarding directory grabbing.. |
|
|
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 |
|
 |
weltall
Joined: 20 Feb 2004 Posts: 310
|
Posted: Sun Oct 15, 2006 1:08 am Post subject: |
|
|
/**
* 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 |
|
 |
AnonymousTipster
Joined: 01 Jul 2005 Posts: 197
|
Posted: Sun Oct 15, 2006 1:23 am Post subject: |
|
|
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 |
|
 |
|
|
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
|