Page 1 of 1

NXC: use of FileFindFirst, FileFindNext ?

Posted: 12 Feb 2011, 17:54
by HaWe
hi,
there are no examples to find about the topics
FileFindFirst, FileFindNext

e.g., my files are:
0001.wpt
0002.wpt
0011.wpt
0015.wpt
so a file name pattern could be ????.wpt

1) can this file search pattern "????.wpt" be used?
2) how will NXC signalize
a) if any first file exists at all or not? (using FileFindFirst)
b) if yes: if any additional file can be found? (using FileFindNext)
c) if end of search has been reached? (using FileFindNext)

can anybody provide help?

Re: NXC: use of FileFindFirst, FileFindNext ?

Posted: 13 Feb 2011, 02:08
by muntoo
I'd rather use ListFilesType. This is the one I use in my NXTFileManager.

You may want to look at an example.

Re: NXC: use of FileFindFirst, FileFindNext ?

Posted: 13 Feb 2011, 11:08
by HaWe
What 'm looking for is something as available by 2 Pascal procedures which work like

Code: Select all

FindFirst(path: string; attr: Byte; var S: TSearchRec)
FindNext(var S: TSearchRec);
(I have been programming with Pascal for 10-20 years)

Code: Select all

program FindFirstDemo;
var S: TSearchRec;
begin
  FindFirst ('*.PAS', faAnyFile, S);
  while DosError =0 do  begin
    WriteLn(S.Name);
    FindNext(S);
  end;
end.
(using NXC sysListFiles (which I just discovered - thx muntoo!) I always get runtime errors, FileFindFirst/Next promises to be more easy to use I assume)

Re: NXC: use of FileFindFirst, FileFindNext ?

Posted: 14 Feb 2011, 16:02
by afanofosc
Here's an example that I have just now put into the example files for the NXC help system.

Code: Select all

task main() {
  byte handle;
  unsigned int result, fsize;
  string fname = "*.ric";
  result = FindFirstFile(fname, handle);
  NumOut(0, LCD_LINE1, result, true);
  int i=1;
  while (result == LDR_SUCCESS) {
    NumOut(0, LCD_LINE2, i, false);
    TextOut(0, LCD_LINE3, fname, false);
    Wait(1500);
//    fname = "";
    result = FindNextFile(fname, handle);
    NumOut(0, LCD_LINE1, result, true);
    i++;
  }
  CloseFile(handle);
  Wait(3000);
}
You should not use ? for a wildcard character.

John Hansen

Re: NXC: use of FileFindFirst, FileFindNext ?

Posted: 14 Feb 2011, 16:17
by HaWe
thank you very much John,
that's very handsome and quite similar to the Pascal syntax I'm used to!
Thx a lot!

ps:
[OT]
do you already know when you will publish the next Brcixcc/NXC release?
[/OT]