|
I wrote some NXC code that runs on the enhanced NBC/NXC firmware. It
demonstrates how to iterate files on the filesystem.
Let me know if you have any questions.
John Hansen
#define LOADER_HANDLE(_x) (_x&0xff)
#define LOADER_ERR_BYTE(_x) ((_x&0xff00)>>8)
unsigned int FindFirst(string pattern, string & output) {
LoaderExecuteFunctionType lef;
lef.Cmd = LDR_CMD_FINDFIRST;
lef.Filename = pattern;
ArrayInit(lef.Buffer, 0, 20);
SysLoaderExecuteFunction(lef);
if (LOADER_ERR_BYTE(lef.Result) == LDR_SUCCESS)
output = ByteArrayToStr(lef.Buffer);
else
output = "File Not Found";
return lef.Result;
}
unsigned int FindNext(byte handle, string & output) {
LoaderExecuteFunctionType lef;
lef.Cmd = LDR_CMD_FINDNEXT;
ArrayInit(lef.Filename, 0, 20);
ArrayInit(lef.Buffer, 0, 20);
lef.Filename[0] = handle;
SysLoaderExecuteFunction(lef);
output = ByteArrayToStr(lef.Buffer);
return lef.Result;
}
task main() {
byte handle;
unsigned int result;
string fname;
result = FindFirst("*.ric", fname);
NumOut(0, LCD_LINE1, result, true);
int i=1;
while (LOADER_ERR_BYTE(result) == LDR_SUCCESS) {
NumOut(0, LCD_LINE2, i, false);
TextOut(0, LCD_LINE3, fname, false);
Wait(500);
handle = LOADER_HANDLE(result);
result = FindNext(handle, fname);
NumOut(0, LCD_LINE1, result, true);
i++;
}
CloseFile(handle);
Wait(3000);
}
|
|
1 Message in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|