

require 'fileutils'


class FileSystem
  include FileUtils

  attr_reader :root

  def initialize( )
    @root = "/"
  end

  def root?(dir=nil)
    pth = File.expand_path(dir||work)
    return true if pth == '/'
    return true if pth =~ /^(\w:)?\/$/
    false
  end 

  def work; Dir.pwd; end

  def ls
    Dir.entries.collect do |f|
      File.directory?(f) ? Dir.new(f) : File.new(f) 
    end
  end

  # Direct access to a directory or file.

  def [](name)
    if File.directory?(name)
      Dir.new(name)
    elsif File.file?(name)
      File.new(name)
    else
      nil
    end
  end

end

