libfatdir.pp 903 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. program libfatdir;
  2. uses
  3. ctypes, nds9, fat;
  4. var
  5. MyDir: PDir;
  6. pent: pdirent;
  7. statbuf: Tstat;
  8. begin
  9. // Initialise the console, required for printf
  10. consoleDemoInit();
  11. if (fatInitDefault()) then
  12. begin
  13. MyDir := opendir('/');
  14. if (MyDir) <> nil then
  15. begin
  16. repeat
  17. pent := readdir(MyDir);
  18. _stat(pent^.d_name, statbuf);
  19. if (strcmp('.', pent^.d_name) = 0) or (strcmp('..', pent^.d_name) = 0) then
  20. continue;
  21. if (S_ISDIR(statbuf.st_mode)) then
  22. iprintf('%s <dir>'#10, pent^.d_name);
  23. if not (S_ISDIR(statbuf.st_mode)) then
  24. iprintf('%s %ld'#10, pent^.d_name, statbuf.st_size);
  25. until pent = nil;
  26. closedir(MyDir);
  27. end else
  28. begin
  29. iprintf ('opendir() failure; terminating'#10);
  30. end;
  31. end else
  32. begin
  33. iprintf('fatInitDefault failure: terminating'#10);
  34. end;
  35. while true do
  36. swiWaitForVBlank();
  37. end.