Jump to content


Photo

Glob


  • Please log in to reply
3 replies to this topic

#1 Clare

Clare

    The Big Wad Bolf.

  • X-treme Team
  • 3295 posts
  • Gender:Female
  • Location:UK

Posted 05 June 2009 - 06:11 AM

Does anyone know if there's a way to determin the difference between files and folders with the GLOB function, or is there a better way to return the contents of a folder?

I have tried this:
CODE
say(chdir("c:\"));

While( (filename = Glob("*")) != "" )
     say(filename);
End;
      
Repeat
     Frame;
Until(key(_ESC))

But that does not appear to distinguish between files and folders returned .

#2 Peter R

Peter R

    Zrzore Gvgyr

  • GP32 Hardcore
  • PipPipPipPipPipPip
  • 9334 posts
  • Gender:Male
  • Location:Somewhere in Wiltshire or Somerset
  • Interests:Programming, Science and Computer Games.

Posted 07 June 2009 - 12:42 AM

No idea. However, you can try and chdir into the returned results which seems to return 0 if a directory and and an int (possibly always positive and maybe its constant also?) when trying to chdir into a file. I have no idea if thats the right way to do it but it seems to work in the quick test i've done.

#3 Sandman

Sandman

    GP32 User

  • Members
  • PipPipPip
  • 48 posts

Posted 07 June 2009 - 02:51 AM

Use Fileinfo.

CODE
#ifdef COMPILER_VERSION
     import "mod_say"
     import "mod_dir"
#endif

Process Main()
Private
     string filename;
Begin
     While( (filename = Glob("*")) != "")
         if(Fileinfo.directory)
             say("[DIR]  " + filename);
         else
             say("[FILE] " + filename);
         end
     End
End


#4 Clare

Clare

    The Big Wad Bolf.

  • X-treme Team
  • 3295 posts
  • Gender:Female
  • Location:UK

Posted 07 June 2009 - 07:23 AM

Thanks Sandman, that's exactly what I am looking for smile.gif