TRANSCODE Explorations into the Code Transcendental.

Taming the file system Zoo

I’m not quite sure I undestand why we have all these classes and modules: Dir, File, FileUtils, FileTest and Pathname. I understand what each does, of course, but I don’t understand why the clearly related functionality has been spread about. I think a single FileSystem class or module would be in order –a system we could use in much the same manner as we use the command shell to work with a file system.

  fs = FileSystem.new
  fs.cd('/')
  entries = fs.ls
  entries.each do |e|
    if fs.directory?(e)
      ...
    else
      fs.open(e) { |f| ... }
    end
  end

It’s not so common that we open files and harbor them, even less so for directories. So the FileSystem can have those defined within it as well, and there’s no reason to even draw them up yourself. FileSystem can do it for you:

  fs['afile.txt']  #=> <#FileSystem::File...>
  fs['adir/']      #=> <#FileSystem::Dir...>

Clear, straightforward and convenient. But best of all, this single point of entry into all things “file system” may lead to more interesting possibilities, in some respect similar to what FUSE offers us in general, only confined to Ruby’s realm.

I also wonder how remote file systems might fit into this… interesting considerations all.