access_dir.pp 802 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. program access_dir;
  2. {$apptype arm9}
  3. {$mode objfpc}
  4. uses
  5. nds9, fat, ctypes;
  6. var
  7. i: integer;
  8. filename: string[255];
  9. handle: P_FILE;
  10. st: stat;
  11. dir: PDIR_ITER;
  12. begin
  13. consoleDemoInit();
  14. printf('fatInit()...');
  15. if (fatInitDefault()) then
  16. begin
  17. printf(#9 + 'Success' + #10);
  18. dir := diropen('/');
  19. if (dir = nil) then
  20. iprintf ('Unable to open the directory.'#10)
  21. else
  22. begin
  23. while dirnext(dir, pchar(@filename), @st) = 0 do
  24. begin
  25. // st.st_mode & _IFDIR indicates a directory
  26. if (st.st_mode and $4000) <> 0 then
  27. iprintf ('%s: %s'#10, ' DIR', pchar(@filename))
  28. else
  29. iprintf ('%s: %s'#10, 'FILE', pchar(@filename));
  30. end;
  31. end;
  32. end else
  33. printf(#9 + 'Failure' + #10);
  34. while true do;
  35. end.