NXC: use of FileFindFirst, FileFindNext ?

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
Post Reply
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

NXC: use of FileFindFirst, FileFindNext ?

Post 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?
muntoo
Posts: 834
Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:

Re: NXC: use of FileFindFirst, FileFindNext ?

Post by muntoo »

I'd rather use ListFilesType. This is the one I use in my NXTFileManager.

You may want to look at an example.
Image

Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE


Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: NXC: use of FileFindFirst, FileFindNext ?

Post 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)
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: NXC: use of FileFindFirst, FileFindNext ?

Post 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
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: NXC: use of FileFindFirst, FileFindNext ?

Post 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]
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest