#58 sys::File

brian Mon 27 Mar 2006

I checked in a basic File class. It's got most of the basics working with an associated test suite:

class File
{
  new make(Str path)
  Bool exists()
  Int size()
  Bool isDir()
  Str path()
  Str name()
  Str basename()
  Str ext()
  File[] list()
  Str[] listNames()
  File join(Str name1, Str name2 := null, Str name3 := null, Str name4 := null,
            Str name5 := null, Str name6 := null, Str name7 := null, Str name8 := null)
  File createFile()
  File createDir()
  Void delete()
  static Str sep()
}

Couple API design issues I would like feedback on:

  • Do you like join returning a File - seems more useful than Ruby/Python which return Str
  • Does createFile/createDir work without confusion vs factory make?
  • Do you agree list is more common than listNames (vs list/listFiles like Java)
  • Is delete just always recursive? Pass flag? Different method?

andy Mon 27 Mar 2006

  1. File.join -> File makes sense to me - though I guess the issue there is that I don't always want/need a file - so stuff like path() would need to work correctly when the file doesn't exist for example.
  2. Not sure what you mean - you mean in order to create a file, first I make() it then call create()? Versus just something like makeCreate()?
  3. Sure (sort of same issue as #1 right?).
  4. Probably default parameter for recursion set to true - that seems like the common case - but should probably still allow some control.

Login or Signup to reply.