How to read information from a dir

slinga

Established Member
Here's a quick question,

How do I gather information from a directory? I want to know the filenames of each file, as well as the size of each file? Any ideas? (and yes for the Saturn) Thanks in advance.
 
No trace of such a function in the SGL. You should try with more low level ones such as those provided by the Sega Basic Library, where I found some good looking prototypes :

Code:
Sint32 CDC_TgetToc(Uint32 *toc);

Sint32 CDC_GetSes(Sint32 sesno, Uint32 *ses);

Sint32 CDC_CdInit(Sint32 iflag, Sint32 stnby, Sint32 ecc, Sint32 retry);

Sint32 CDC_CdOpen(void);

Sint32 CDC_DataReady(Sint32 dtype);

Sint32 CDC_DataEnd(Sint32 *cdwnum);

...

Sint32 CDC_ChgDir(Sint32 filtno, Sint32 fid);

Sint32 CDC_ReadDir(Sint32 filtno, Sint32 fid);

Sint32 CDC_GetFileScope(Sint32 *fid, Sint32 *infnum, Bool *drend);

Sint32 CDC_TgetFileInfo(Sint32 fid, CdcFile *file);

Sint32 CDC_ReadFile(Sint32 filtno, Sint32 fid, Sint32 offset);

Sint32 CDC_AbortFile(void);

...

etc.

look in this SBL header :

SBL6/SEGALIB/INCLUDE/SEGA_CDC.H

Good luck
 
hmm... i've heard about this CDC stuff but did someone ever pick up a doc on this? since my header files don't show much because of the japanese comments i can't figure out how to get CDDA-Tracks (NO CDDA-FILES!!) playing. there are functions i know that but how to use them?
blink.gif
 
i remember having downloaded those file from your site but i don't that i already had them... anyway, you these two will certainly help me with my contest project.
wink.gif
 
Hey guys,

I read through the documentation above but I couldn't find a function that did what I required. So I decided to try something like this:

Code:
void cdToBackup(int device, BupStat stat)

{ 

 Sint32 numSaves=0;

 slPrintHex((numSaves), slLocate(5,numSaves+12));

	while(GFS_IdToName(numSaves)!=NULL)

	{

  slPrintHex((numSaves), slLocate(5,numSaves+4));

  slPrint(GFS_IdToName(numSaves), slLocate(5,numSaves+4));

	}

 slPrintHex((numSaves), slLocate(5,numSaves+11));

}

Which of course doesn't work...I'm just trying to have the saturn display filenames from the cd right now. I've included the proper library, but I'm not sure if I have to initialize the GFS library somewhere. Later on I'll have to do some creative filename converting...(Saturn backup ram files have to be 11 characters, saturn cds apparently only support 8 character name + 3 character extension...if GFS_IdToName displays the extension I'll be fine...if not I'm screwed <_< )

BTW, am I the only person having difficulty with the documentation? I'm guessing it was translated from Japanese to English, and lost some of its clarity in the translation. Also what's with all the errors? As if things weren't confusing enough.
 
This doesn't work either:

Code:
void cdToBackup(int device, BupStat stat)

{ 

 Uint32 cdWork[GFS_WORK_SIZE(MAX_FILE)/4]; // Allocates space for files

 GfsDirTbl dirTable;   // Holds Directory control info

 GfsDirId dir[MAX_DIR];  // Directory storage info

 Sint32 numSaves=2;   // The number of saves

 GFS_DIRTBL_TYPE(&dirTable) = GFS_DIR_ID;

 GFS_DIRTBL_NDIR(&dirTable) = MAX_DIR;

 GFS_DIRTBL_DIRID(&dirTable) = dir;

 GFS_Init(MAX_FILE, cdWork, &dirTable);

 GFS_SetDir(&dirTable);

 slPrintHex((numSaves), slLocate(5,numSaves+12));

	while(GFS_IdToName(numSaves)!=NULL)

	{

  slPrintHex((numSaves), slLocate(5,numSaves+4));

  slPrint(GFS_IdToName(numSaves), slLocate(5,numSaves+4));

  numSaves++;

	}

 slPrintHex((numSaves), slLocate(5,numSaves+11));

}

Grrrr
 
I checked a little the source I made for the SMS Emu, but accessing the file list was really easy. here is a small part of the code :

Code:
Sint32 stat;

stat= slCdChgDir(dirname);

file_max = stat-2;

stat contains the number of files (including ".." and ".") so the real number of iles is in file_max.

to get the filenames :

Code:
sprintf(toto,"filename: %s", GFS_IdToName(file_id));

slPrint(toto,slLocate(25,1));

file_id moves from 2 to stat (or something like that)

I'm sure that will hep you.
 
I think your code was good, I think I'm doing something idiotic:

Code:
void cdToBackup(int device, BupStat stat)

{ 

 Uint32 cdWork[GFS_WORK_SIZE(MAX_FILE)/4]; // Allocates space for files

 GfsDirTbl dirTable;   // Holds Directory control info

 GfsDirId dir[MAX_DIR];  // Directory storage info

 Sint32 numSaves;   // The number of saves

 Sint32 ret, temp;

 char* file;

 GFS_DIRTBL_TYPE(&dirTable) = GFS_DIR_ID;

 GFS_DIRTBL_NDIR(&dirTable) = MAX_DIR;

 GFS_DIRTBL_DIRID(&dirTable) = dir;

 ret = GFS_Init(MAX_FILE, cdWork, &dirTable);

 if(ret<=2)

  {

	slPrint("Error!!!", slLocate(5,7));

	pressStart();

  }

 numSaves = slCdChgDir("SAVES");

 for( temp = 3; temp <numSaves; temp++)

 {

	sprintf(file,"filename: %s", GFS_IdToName(temp));

	slPrint(file,slLocate(3+temp,1));

	slPrintHex(temp, slLocate(20,temp));

 }

}

I'm going to keep on trying to debug this...
 
Hmmm numSaves doesn't seem to be holding the correct value of saves. When I print it I get: FFFFFFF8
 
I got it to work like this (snippets from my program):

Code:
#include "sgl_cd.h" // Required for cd access

#define MAX_FILE 20 // Needed for CD functions

Code:
void cdToBackup(int device, BupStat stat)

{ 

        slCdInit(MAX_FILE, dirwork); // initializes cd

	slCdChgDir("SAVES"); // Changes to SAVES directory

    	// Displays all the saves on the CD

	for(temp = 2;GFS_IdToName(temp)!=NULL; temp++)

	{

  slPrint(GFS_IdToName(temp),slLocate(5,temp+4));

	}	

	// Displays go back option

   slPrint("Back", slLocate(5, temp+4));

0 is reserved for parent directory, and 1 is reserved for the directory, that's why I started the for loop at 2. GFS_IdToName is NULL when the file doesn't exist (or I so think...). I just gotta write a function that converts 8.3 filenames into 11 character filenames and I'm done...
 
Back
Top